vscode-java-test icon indicating copy to clipboard operation
vscode-java-test copied to clipboard

Code coverage: exclude specified classes

Open pcarterubc opened this issue 1 year ago • 6 comments

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.

pcarterubc avatar Jan 16 '25 23:01 pcarterubc

i get the same problem, can't exclude target folders from coverage

ericPavone avatar Feb 14 '25 14:02 ericPavone

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.

sterling000 avatar Mar 27 '25 21:03 sterling000

Same problem

regis-amaral avatar Jun 04 '25 14:06 regis-amaral

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.

pcarterubc avatar Jul 29 '25 23:07 pcarterubc

I've ran into this today and am in the process of submitting a PR to support this functionality. Stand by!

PR: #1809

glektarssza avatar Nov 04 '25 20:11 glektarssza

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!

github-actions[bot] avatar Nov 12 '25 23:11 github-actions[bot]