jacoco test coverage filtering non business classes

Keywords: Programming xml Java encoding Selenium

Before that Interface test code coverage (jacoco) scheme When I missed something, this article will make up for it. In the process of using jacoco to do interface code coverage test, there is a problem: there is too much information in the test report, which is very messy and not targeted. Many of them are config, bean and adapter classes, and most of them have no business code. The coverage calculated is affected greatly and not accurate enough.

This paper introduces the problem of how to filter the jacoco code coverage test report. After consulting the data, there are roughly two schemes: one is to filter in the jacoco configuration, and the other is to delete useless class files in the class folder.

After some consideration, the first option was adopted for the following reasons:

  1. The second scheme is irreversible. If the coverage of a certain moudel is counted, then it cannot be realized directly when other moudels are counted;
  2. The second one is troublesome, and the rules need to be implemented by script.
  3. It is not easy to combine with the existing framework, so it is not easy to realize this function in the reporting framework.

The first scheme mainly modifies the configuration of the build file:

<?xml version="1.0" ?>
<project name="studentpad-middle-toc" basedir="/home/jmsmanager/report/studentpad-middle-toc"
    xmlns:sonar="antlib:org.sonar.ant" default="all">
    <!--Project name-->
    <property name="projectName" value="studentpad-middle-toc"/>
    <!--Jacoco Installation path for-->
    <property name="jacocoantPath" value="/home/jmsmanager/jacoco/lib/jacocoant.jar"/>
    <!--Path to generate coverage report-->
    <property name="reportfolderPath" value="${basedir}/report/"/>
    <!--Remote service's ip If there are more than one address, you can set more than one, name Need to be modified-->
    <property name="server_ip" value=""/>

    <!--Procedure to be tested.class File path-->
    <property name="waterommpClasspath" value="/xdfapp/${projectName}/webapps/ROOT/WEB-INF/classes/com/noriental/moudle"/>

    <!--Source file path of the program to be tested-->
    <property name="mcmSrcpath" value="${basedir}/source/${projectName}/workspace/src/main/java"/>
    <!--Jacoco Directory-->
    <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
        <classpath path="${jacocoantPath}" />

    <!--merge task´╝îWhen there are multiple programs to be tested, all.exec file merge Become one-->
    <target name="merge" depends="dump">
        <jacoco:merge destfile="jacoco.exec">
            <fileset dir="${basedir}" includes="*.exec"/>
<!--dump task:
           According to the previously configured ip Address, and port number, access the target service, and generate.exec Documents.-->

    <target name="dump">
        <!-- reset="true"Means at dump When finished, reset jvm Coverage data in is empty. append="true"Means dump Come out exec File is incremental -->
        <jacoco:dump address="${server_ip}" reset="true" destfile="${basedir}/jacoco.exec" port="12345" append="false"/>

    <!--report task:
               According to the source code path and.class File path,
      according to dump After, the generated.exec Files, generating final html Coverage report.-->
    <target name="report">
        <delete dir="${reportfolderPath}" />
        <mkdir dir="${reportfolderPath}" />

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


            <structure name="JaCoCo Report">

                <group name="Student middle tier code coverage">
                        <fileset dir="${waterommpClasspath}">
				<exclude name="**/vo/*.class"/>

                    <sourcefiles encoding="UTF-8">
                    	<fileset dir="${mcmSrcpath}">

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

    <target name="all" />


It is mainly filtered in the exclude tab. If you exclude large blocks, you can also filter when specifying the classfilepath.

  • Solemnly declare that "FunTester" is launched, welcome to pay attention to communication and prohibit third party reprint. More original articles: FunTester 18 original albums , please contact Fhaohaizi@163.com .

Hot text selection

Posted by phpBuddy on Thu, 21 May 2020 20:22:57 -0700