Reputation: 321
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.*">
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.
Any suggestions how how to get jacoco to exclude all tests in this setup?
thanks.
Upvotes: 9
Views: 9711
Reputation: 321
Specifying classes with jacoco:coverage
excludes them from coverage, so they show up as having 0% coverage in the report.
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>
Upvotes: 23