Code coverage: exclude specified classes
Is there a way to configure the code coverage tool to exclude certain classes from coverage? I know there's a java.test.coverage property but haven't been able to find any details on how to configure it, other than the appendResult property.
If there is currently no way to do this, it would be great to add it as a new feature.
i get the same problem, can't exclude target folders from coverage
Same problem, I have a few integration test and sample classes with main functions in my project that I don't want to track coverage on because it wouldn't make sense, they are distorting the results.
Same problem
Just discovered that jacoco has built-in support for handling this issue. See this post for details. Note that you can also use the annotation to exclude an entire class from coverage.
I've ran into this today and am in the process of submitting a PR to support this functionality. Stand by!
PR: #1809
Hi @pcarterubc, I'm an AI Support assistant here to help with your issue. While the team reviews your request, I wanted to provide some possible tips and documentation that might help you in the meantime.
There’s currently no built-in support in vscode-java-test to exclude classes via java.test.coverage. You can work around this at the build tool level:
• Maven (JaCoCo):
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>com/example/IgnoreMe*</exclude>
</excludes>
</configuration>
</plugin>
https://www.jacoco.org/jacoco/trunk/doc/maven.html
• Gradle (JaCoCo):
jacocoTestReport {
afterEvaluate {
classDirectories.setFrom(files(
classDirectories.files.collect {
fileTree(dir: it, exclude: ['com/example/IgnoreMe*'])
}
))
}
}
https://docs.gradle.org/current/userguide/jacoco_plugin.html
If you’d like native support in vscode-java-test, please upvote/comment on the feature request:
• Code coverage report discussion (feature request) https://github.com/microsoft/vscode-java-test/issues/387
Other references with low confidence
• Bug: Coverage not shown for subprojects in Explorer and Testing tab – discusses internal handling of coverage results, but doesn’t address exclusion. https://github.com/microsoft/vscode-java-test/issues/1676
The team will respond to your issue shortly. I hope these suggestions are helpful in the meantime. If this comment helped you, please give it a 👍. If the suggestion was not helpful or incorrect, please give it a 👎. Your feedback helps us improve!