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

Branch code coverage not working properly

Open lollolg opened this issue 10 months ago • 2 comments

I recently discovered the branch code coverage and I think it would be a very useful tool, however at the moment is buggy:

Image

In the case above it tells me the branch 6 has no coverage, which is the case when the first three statements are false.

Image

Here it tells me branch 2 is not covered, which is when the statement is false.

First of all maybe the fact that the statements are divided by lines shouldn't truncate the number of branches... If I put all statements in one line it would tell me that branch 8 is not covered (when all statements are false)

But most importantly as you can see branch 8 would be the one actually covered because the 'else' statement is all green. I could give you other examples where this is evident. Essentially what I am trying to say that if one of the branches is not covered at the moment the extension just says the last branch is not covered, when in fact in the case I gave you earlier I am pretty sure branch 7 (when now.equals(orarioFineEsec) equals true) is not covered, but I wouldn't know on the info that is given here.

lollolg avatar Feb 04 '25 15:02 lollolg

Any news on this?

lollolg avatar Mar 03 '25 15:03 lollolg

Hi @lollolg, 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.

Underlying Cause

This is a limitation of the current VS Code Test Coverage API: it only reports line/statement coverage, not full branch coverage, so branch counts are mis-mapped when conditions span multiple lines.

Workarounds & References

  • For background on the API limitation, see:
    • Code coverage: execution count not correct (shows VS Code only exposes line/statement coverage) • https://github.com/microsoft/vscode-java-test/issues/1698#issuecomment-2167026090
  • To track upcoming support for richer coverage (including branches) in VS Code itself, follow:
    • VS Code test coverage API enhancement • https://github.com/microsoft/vscode/issues/123713
  • As a temporary workaround, generate and view branch coverage via your build tool’s HTML report (e.g., JaCoCo), or use an alternate VS Code extension such as Coverage Gutters that parses JaCoCo XML.
Other references with low confidence
  • Code coverage report ? (discusses waiting on VS Code coverage API and a postLaunchTask workaround) • https://github.com/microsoft/vscode-java-test/issues/387#issuecomment-1129995034

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]