Im generating a jacoco coverage report using the following target :
<target name="report" depends="test">
<!-- This task needs the collected execution data and ... -->
<executiondata>
<file file="${result.exec.file}" />
</executiondata>
<!-- the class files and optional source files ... -->
<structure name="JaCoCo Ant Example">
<classfiles>
<fileset dir="${result.classes.dir}" />
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${src.dir}" >
<exclude name="**/*Test*.class"/>
</fileset>
</sourcefiles>
</structure>
<!-- to produce reports in different formats. -->
<html destdir="${result.report.dir}" />
<csv destfile="${result.report.dir}/report.csv" />
<xml destfile="${result.report.dir}/report.xml" />
</jacoco:report>
</target>
The problem is that the report takes into account the code from unit tests and I consider this fact a mistake. This way, your line coverage percent and instruction coverage will be artificially increased(because test lines are considered 100% covered) and report correctness is pretty affected. I tried to add this tag
<exclude name="**/*Test*.class"/
under fileset tag, hoping that testClasses will be excluded, but it doesnt works. Do you have any ideas for my problem? I want to avoid programmatically report modification. Thanks!
You need to exclude the Test class files from the classfiles
fileset:
<structure name="JaCoCo Ant Example">
<classfiles>
<fileset dir="${result.classes.dir}">
<exclude name="**/*Test*.class"/>
</fileset>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${src.dir}" />
</sourcefiles>
</structure>
See documentation:
"Note that the classfiles and sourcefiles elements accept any Ant resource collection. Therefore also filtering the class file set is possible and allows to narrow the scope of the report, for example:
<classfiles>
<fileset dir="classes">
<include name="org/jacoco/examples/important/**/*.class"/>
</fileset>
</classfiles>
This is because the actual report is done from the classfiles
. The sourcefiles
are there to include highlighted source code in the report - as of course the human eye can't read compiled code.
Again from the documentation:
classfiles: Container element for Ant resources and resource collections that can specify Java class files, archive files (jar, war, ear etc. or Pack200) or folders containing class files. Archives and folders are searched recursively for class files.
sourcefiles: Optional container element for Ant resources and resource collections that specify corresponding source files. If source files are specified, some report formats include highlighted source code. Source files can be specified as individual files or as source directories.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments