[英]JaCoCo coverage report setups(exclude test classes)
Im generating a jacoco coverage report using the following target : 我使用以下目标生成了jacoco覆盖率报告:
<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. 这样,您的行覆盖率和指令覆盖率将被人为增加(因为测试行被视为100%覆盖了),并且报告的正确性受到很大影响。 I tried to add this tag 我试图添加此标签
<exclude name="**/*Test*.class"/
under fileset tag, hoping that testClasses will be excluded, but it doesnt works. 在文件集标签下,希望将testClasses排除在外,但它不起作用。 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: 您需要从类文件文件classfiles
排除测试类文件:
<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和sourcefiles元素接受任何Ant资源集合。因此,也可以过滤类文件集,并允许缩小报告的范围 ,例如:
<classfiles>
<fileset dir="classes">
<include name="org/jacoco/examples/important/**/*.class"/>
</fileset>
</classfiles>
This is because the actual report is done from the classfiles
. 这是因为实际报告是从classfiles
完成的。 The sourcefiles
are there to include highlighted source code in the report - as of course the human eye can't read compiled code. sourcefiles
在报告中包含突出显示的源代码-当然,人眼无法阅读编译后的代码。
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. classfiles :Ant资源和资源集合的容器元素,可以指定Java类文件,归档文件(jar,war,ear等。或Pack200)或包含类文件的文件夹。 Archives and folders are searched recursively for class files. 递归搜索档案和文件夹中的类文件。
sourcefiles : Optional container element for Ant resources and resource collections that specify corresponding source files. sourcefiles :Ant资源和资源集合的可选容器元素,用于指定相应的源文件。 If source files are specified, some report formats include highlighted source code . 如果指定了源文件,则某些报告格式将包括突出显示的源代码 。 Source files can be specified as individual files or as source directories. 可以将源文件指定为单个文件或源目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.