0
votes

Gradle 'Jacoco' plugin's 'jacocoTestReport' generates code coverage report for all the unit tests.

How should I proceed to create a gradle task to generate 'Jacoco' code coverage reports of each unit test individually?

HelloWorld.java

HelloWorldTest.java contains Test1, Test2, Test3 methods

I want to generate individual Jacoco code coverage report for Test1, Test2, Test3 methods.

1

1 Answers

1
votes

During running of the tests, Jacoco instruments the classes and records what was called. The task of type JacocoReport then just takes these results and makes an XML, HTML or CSV report out of them.

So to get what you want, you need to add several Test tasks that execute the single tests and then add several JacocoReport tasks that point to the different result files, then you can generate these reports in one run.

If you only want to do this manually, I think you can just call Gradle like gradlew test --tests HelloWorld.Test1 jacocoTestReport.

In the latter case it might be necessary to also set test { jacoco { append false } } to not have the results of former runs in the report.