jacoco在使用ant时不排除类 [英] jacoco not excluding classes when using ant
问题描述
我很难找到一个雅各布/准蚂蚁目标,以将班级排除在覆盖范围之外.我可以用类似这样的东西来排除软件包:
I'm having trouble getting a jacoco/junit ant target to exclude classes from coverage. I can get it to exclude packages though with something like this:
<jacoco:coverage destfile="${coverage.reports.dir.xml}/output.jacoco" excludes="foo.*:bar.fiz.*:my.long.package.name.*">
这不会排除我的测试类,因为测试类与他们测试的类在同一包中.我已经厌倦了用正则表达式排除测试类,但这是行不通的.
This doesn't exclude my test classes though because the test classes are in the same package as the classes they test. I've tired this to exclude the test classes with a regex, but it doesn't work.
<jacoco:coverage destfile="${coverage.reports.dir.xml}/output.jacoco" excludes="foo.*:bar.fiz.*:**/Test.*:**/Tests.*">
我也尝试只在报告任务中包含我想要的类,但是由于我们的测试类位于不起作用的相同程序包中.我们的构建将所有类放在同一目录中,例如buildRoot/classes/ProjectName.因此buildRoot/classes/ProjectName/foo将包含用于测试和非测试类的编译类.
I also tried just including the classes I want in the report task, but since our test classes are in the same packages that doesn't work. Our build puts all the classes in the same directory, like buildRoot/classes/ProjectName. So buildRoot/classes/ProjectName/foo will contain the compiled classes for tests and non-test classes.
任何建议如何使jacoco排除此设置中的所有测试?
Any suggestions how how to get jacoco to exclude all tests in this setup?
谢谢.
推荐答案
使用jacoco:coverage
指定类会将其排除在覆盖范围之外,因此它们在报告中的覆盖率显示为0%.
Specifying classes with jacoco:coverage
excludes them from coverage, so they show up as having 0% coverage in the report.
要同时从JaCoCo报告中排除这些类,您需要使用classfiles文件集任务并将其排除在jacoco:report
ant任务中.
In order to also exclude these classes from the JaCoCo report, you need to use classfiles fileset task and exclude them in the jacoco:report
ant task.
<jacoco:report>
<executiondata>
<file file="${coverage.reports.dir.xml}/merged-jacoco.exec"/>
</executiondata>
<structure name="Unit Tests ${unit.test.run.ts}">
<classfiles>
<fileset dir="${build.root}/classes/ProjectName/" >
<exclude name="**/*Test*.class" />
</fileset>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${src.root}/ProjectName/src/main"/>
</sourcefiles>
</structure>
<html destdir="${coverage.reports.dir.html}"/>
</jacoco:report>
这篇关于jacoco在使用ant时不排除类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!