Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Code Coverage in Visual Studio Code

I am using VSC for my Java project with maven help. I would like to use a Code Coverage tool but I lost the directions in the many possibilities you have.
My goals are:

  • run the Code Coverage goal with Maven;
  • Display the test coverage in VSC with a plugin like Coverage Gutter

Which Code Code coverage tool to use?
Can someone show me the right Maven plugin and the way to configure VSC?

Thanks,
S.

like image 226
Stefano Bossi Avatar asked Aug 22 '18 09:08

Stefano Bossi


People also ask

How do I get code coverage in VS Code?

On the Test menu, select Analyze Code Coverage for All Tests. You can also run code coverage from the Test Explorer tool window. Show Code Coverage Coloring in the Code Coverage Results window. By default, code that is covered by tests is highlighted in light blue.

Is Visual Studio Code OK for Java?

You can use VS Code to read, write, run, and debug Java source file(s) without creating a project. VS Code for Java supports two modes, lightweight and standard.


Video Answer


1 Answers

For now, I don't think there is a way to show coverage inline for java code. This is not really an answer to your question but it may help. You can run tests (maybe create a task in vscode) then watch code coverage report in the browser. For gradle it is:

./gradlew test jacocoTestReport

And then check the report at build/TestCoverageReport/test/html/index.html

You can do that also easily with maven.

like image 91
zguesmi Avatar answered Sep 22 '22 09:09

zguesmi