I missed a few things in my previous work on the Interface test code Coverage (JACOCO) solution, and this article will fill in the gaps. In the process of testing interface code coverage with Jacoco, I encountered a problem: there was too much information in the test report, which was disorganized and not targeted. Most of them were config, bean and adapter classes, and most of them had no business code. The statistical coverage was greatly affected and not accurate enough.

The problem of how to filter the jacoco code coverage test report is introduced here. After reviewing the data, there are two possible solutions: one is to filter in the Jacoco configuration, and the other is to delete the useless class files in the class folder.

After some consideration, we decided to adopt the first option for the following reasons:

  1. The second option is irreversible, if you count one of thesemoudelCoverage, after the other statisticsmoudelIs not directly realized;
  2. The second is a bit trickier, and the rules need to be scripted.
  3. It is not well combined with the existing framework, so it is impossible to implement this function easily and quickly in the report framework.

The first option is to modify the configuration of the build file:

<? The XML version = "1.0"? > <project name="studentpad-middle-toc" basedir="/home/jmsmanager/report/studentpad-middle-toc" xmlns:jacoco="antlib:org.jacoco.ant" xmlns:sonar="antlib:org.sonar.ant" default="all"> <! --> <property name="projectName" value="studentpad-middle-toc"/> <! - Jacoco installation path - > < property name = "jacocoantPath" value = "/ home/jmsmanager/Jacoco/lib/jacocoant jar" / > <! < Property name="reportfolderPath" value="${basedir}/report/"/> <! If there are multiple IP addresses for the remote server, you can set multiple IP addresses. The name must be changed. Class file path --> <property name="waterommpClasspath" value="/xdfapp/${projectName}/webapps/ROOT/WEB-INF/classes/com/noriental/moudle"/> <! ${projectName}/workspace/ SRC /main/ Java "/> <! - Jacoco directory - > < taskdef uri = "antlib: org. Jacoco. Ant" resource = "org/Jacoco/ant/antlib. XML" > < the classpath path="${jacocoantPath}" /> </taskdef> <! -- Merge task, when there are multiple applications under test, <target name="merge" depends="dump"> <jacoco:merge destfile="jacoco.exec"> <fileset dir="${basedir}" includes="*.exec"/> </jacoco:merge> </target> <! --dump task: access the target service based on the IP address and port number, and generate an. Exec file. --> <target name="dump"> <! -- reset="true" resets coverage data in the JVM to null after the dump is complete. <jacoco: address="${server_ip}" reset="true" destfile="${basedir}/jacoco.exec"  port="12345" append="false"/> </target> <! -- Report task: according to the previously configured source code path and. Class file path, according to the dump, generated by the exec file, the final HTML coverage report. --> <target name="report"> <delete dir="${reportfolderPath}" /> <mkdir dir="${reportfolderPath}" /> <jacoco:report> <executiondata> <file file="${basedir}/jacoco.exec" /> </executiondata> <structure name="JaCoCo Report"> <group Name =" student middle layer code coverage "> <classfiles> <fileset dir="${waterommpClasspath}"> <exclude name="**/vo/*.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> <target name="all" /> </project>Copy the code

The filter is mainly in the exclude tag, or if large blocks are excluded, it can also be filtered when classFilepath is specified.


  • Solemnly declare: “FunTester” first, welcome to pay attention to exchange, prohibit third party reprint. More original articles:18 original albums by FunTesterPlease contact for cooperation[email protected].

Hot article selected

  • Linux performance monitoring software Netdata Chinese version
  • Graphic HTTP brain map
  • How does JMeter simulate different network speeds
  • Mobile phone verification code Login performance test
  • Select * from List (null)
  • Programming thinking for everyone
  • The Definitive Guide to Java Performance
  • How to become a Full stack automation engineer
  • Selenium Parallel Testing basics
  • Selenium parallel testing best practices