- Attach and configure a JaCoCo agent to the JVM which you will run your integration tests with. To do so, have a look at the detailed JaCoCo documentation to attach the agent: via a command line, using the JaCoCo Maven plugin or using the JaCoCo Ant task.
- Run your automated or manual integration tests within this JVM. At the end of the execution, JaCoCo will dump the code coverage report in the destination you have set in step 1.
- Configure Sonar SonarQube to reuse this JaCoCo report. In your project properties file (or directly in the command line), add the
sonar.jacoco.itReportPathproperty with the path to the JaCoCo IT coverage report as a value.
- Run an analysis to feed Sonar with the information provided by the JaCoCo report.
- Browse the results on the Sonar web interface. On a project dashboard, you can add the Integration test coverage widget:
As usual, drilldown is a drilldown is available from this widget. At the file level, you can access detailed code coverage by integration tests on the Coverage tabCoverage perspective:
Combining Code Coverage
with Unit and Integration Tests
Since Sonar 3.3, Sonar automatically computes the The overall code coverage (combination of code coverage by unit tests and integration tests) is automatically computed. This feature is enable enabled when both code coverage reports (UT + IT) are generated with JaCoCo.
|If coverage by unit tests is not computed with JaCoCo, overall coverage = integration tests test coverage.|
- /projects/languages/java/code-coverage/combined ut-it/combined-ut-it-sonar-runner-jacoco
- /projects/languages/java/code-coverage/combined ut-it/combined-ut-it-multimodule-maven-jacoco
See also the Measure Coverage by Integration Tests with Sonar – Updated blog post.