单元测试代码覆盖率的浅谈     https://blog.csdn.net/zyou1986/article/details/80496509

#!/bin/bash
cd ${WORKSPACE}/${JOB_BASE_NAME}
sudo ${MAVENHOME}/bin/mvn org.jacoco:jacoco-maven-plugin:prepare-agent -f pom.xml -s ${MAVENHOME}/tmp/settings.xml -gs ${MAVENHOME}/tmp/settings.xml clean test -Dautoconfig.skip=true -Dmaven.test.skip=false -Dmaven.test.failure.ignore=true

/**
* 执行单元测试,并收集结果
* @return
*/
def junitTest() {
def junitTestSh = libraryResource encoding: 'yss', resource: junittest
sh(script: "${junitTestSh}${shellMsgToWrite}", label: '执行单元测试', returnStdout: needShellReturn)
dir("${JOB_BASE_NAME}") {
junit "**/target/surefire-reports/TEST-*.xml"
//jacoco指标参数https://jenkins.io/doc/pipeline/steps/jacoco/
jacoco changeBuildStatus: true,
maximumClassCoverage: "${classCoverage}",
maximumMethodCoverage: "${methodCoverage}",
maximumBranchCoverage: "${branchCoverage}",
maximumLineCoverage: "${lineCoverage}"

//archiveArtifacts artifacts: '**/target/surefire-reports/TEST-*.xml', fingerprint: true
}
}
单元测试报告:https://blog.csdn.net/hemin1003/article/details/90521447
覆盖率报告:https://my.oschina.net/fastjrun/blog/3114088

接口测试代码覆盖率(jacoco)方案分享

https://mp.weixin.qq.com/s/D73Sq6NLjeRKN8aCpGLOjQ
https://blog.csdn.net/fjl19900121/article/details/80984632
https://blog.csdn.net/fjl19900121/article/details/80984632
ant执行代码覆盖率工具的build.xml

<?xml version="1.0" ?>

<project name="user-center" basedir="/home/jmsmanager/report/user-center"
    xmlns:jacoco="antlib:org.jacoco.ant"
    xmlns:sonar="antlib:org.sonar.ant" default="all">
    <!--项目名-->
    <property name="projectName" value="user-center"/>
    <!--Jacoco的安装路径-->
    <property name="jacocoantPath" value="/home/jmsmanager/jacoco/lib/jacocoant.jar"/>
    <!--生成覆盖率报告的路径-->
    <property name="reportfolderPath" value="${basedir}/report/"/>
    <!--远程服务的ip地址,如有多个,可设置多个,name需修改-->
    <property name="server_ip" value="127.0.0.1"/>

    <!--待测程序.class文件路径-->
    <property name="waterommpClasspath" value="/home/jmsmanager/report/${projectName}/source/BOOT-INF/classes/com/noriental/center/moudle/"/>

    <!--待测程序源码文件路径-->
    <property name="mcmSrcpath" value="${basedir}/source/src/main/java"/>
    <!--Jacoco所在目录-->
    <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
        <classpath path="${jacocoantPath}" />
    </taskdef>

    <!--merge task,当有多个待测程序时,生成报告前需将所有.exec文件merge成一个-->
    <target name="merge" depends="dump">
        <jacoco:merge destfile="jacoco.exec">
            <fileset dir="${basedir}" includes="*.exec"/>
        </jacoco:merge>
    </target>
    <!--dump任务:            根据前面配置的ip地址,和端口号,访问目标服务,并生成.exec文件。-->

    <target name="dump">
        <!-- reset="true"是指在dump完成之后,重置jvm中的覆盖率数据为空。append="true"是指dump出来的exec文件为增量方式 -->
        <jacoco:dump address="${server_ip}" reset="false" destfile="${basedir}/jacoco.exec" port="12347" append="true"/>
    </target>

    <!--report任务:                根据前面配置的源代码路径和.class文件路径,       根据dump后,生成的.exec文件,生成最终的html覆盖率报告。-->
    <target name="report">
        <delete dir="${reportfolderPath}" />
        <mkdir dir="${reportfolderPath}" />

        jacoco:report
            <executiondata>
                <file file="${basedir}/jacoco.exec" />

            </executiondata>

            <structure name="JaCoCo Report">

                <group name="用户中心覆盖率报告">
                    <classfiles>
                        <fileset dir="${waterommpClasspath}">
                                <exclude name="**/request/*.class"/>
                                <exclude name="**/response/*.class"/>
                        </fileset>
                    </classfiles>
            <sourcefiles encoding="UTF-8">
                        <fileset dir="${mcmSrcpath}">
                      </fileset>
                    </sourcefiles>
                </group>
            </structure>

            <html destdir="${reportfolderPath}" encoding="utf-8" />
            <csv destfile="${reportfolderPath}/report.csv" />
            <xml destfile="${reportfolderPath}/report.xml" />
        </jacoco:report>
    </target>
</project>

 

与流水线结合:https://www.jianshu.com/p/1a13d36a86d4

增量实现代码覆盖率 https://www.jianshu.com/p/50c5cc021396

 

 

Jacoco+docker+ant环境搭建  https://developer.aliyun.com/article/740544?spm=a2c6h.12873581.0.0.5ab21febeF1zzh

有项目代码的实例  https://blog.csdn.net/u013177381/article/details/87861305

diff-cover 用 python 开发的开源工具,github 地址是 https://github.com/Bachmann1234/diff-cover


php的代码覆盖率工具设计:https://www.it603.com/js/91.html 代码:https://github.com/woojean/PHPCoverage

posted on 2020-03-04 18:17  温暖的阳光  阅读(379)  评论(0编辑  收藏  举报