Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

There are two different ways to feed SonarQube TM with information on unit tests execution and code coverage:

  • Using its embedded engine to let SonarQube TM directly launch the unit tests execution and code coverage. Then, the analyzer will automatically fed the database with data exported from the generated reports.
  • Reusing existing reports that have been previously generated by external tools.

...

Using SonarQube

...

Embedded Engine

Maven supports this mode with the following code coverage tools: JaCoCo, Cobertura, Emma and Clover.

The SonarQube TM Ant Task and the SonarQube TM Runner do not support this mode.

Note
titleCompile

Before running an analysis with JaCoCo, the source code has to be compiled.

 

First, tell SonarQube TM to execute the unit tests and the code coverage tool:

...

With Maven, then, you just have to tell SonarQube TM which code coverage engine you wish to use: jacoco or cobertura or emma or clover.

...

Note that this property can be set at SonarQube TM instance level through the web interface: Settings > Configuration > General Settings > Java.

...

Mapping of Unit Tests and Covered Code

Since SonarQube TM 3.5, it is possible to display the mapping of unit tests and covered code. The objective is to answer the following questions:

...

Every analyzer supports this reusing reports mode.

To be reused by SonarQube TM :

  • The tests execution reports have to comply to the JUnit XML format.
  • The code coverage reports have to be generated by either JaCoCo, Emma, Cobertura or Clover.
Sample projects are available on github that can be browsed or downloaded:

First, tell SonarQube TM to reuse existing reports:

...

Code Block
languagehtml/xml
<property name="sonar.dynamicAnalysis" value="reuseReports" />

With SonarQubeTM Runner SonarQubeRunner in your sonar-project.properties file:

...

Test Execution Reports

Tell SonarQube TM where your unit tests execution reports are: absolute or relative path to the directory containing your reports

...

Code Block
languagehtml/xml
<property name="sonar.surefire.reportsPath" value="[baseDir]/myReports/myExecutionReports" />

With SonarQube TM Runner in your sonar-project.properties file:

...

Code Coverage Report 

First, tell SonarQube TM which code coverage engine has been used to generate the reports: jacoco or cobertura or emma or clover.

Code Block
languagehtml/xml
<sonar.java.coveragePlugin>jacoco or cobertura or emma or clover</sonar.java.coveragePlugin>
 
Prior to SonarQube 3.4, the property was sonar.core.codeCoveragePlugin.

Then, tell SonarQube TM where to get the code coverage reports:

...

Code Block
languagehtml/xml
<property name="sonar.jacoco.reportPath" value="[baseDir]/myReports/myCodeCoverageReport" />

With SonarQubeTM Runner SonarQubeRunner in your sonar-project.properties file:

...

...