Versions Compared

Key

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

...

Usage

Coverage and integration tests report format

The project for which you want to import coverage data and integration tests coverage data should contain an XML file complying with the attached XSD schema.
It should look like the following sample:

Code Block
languagexml
<coverage version="1">
  <file path="src/main/java/com/example/MyClass.java">
    <lineToCover lineNumber="2" covered="false"/>
    <lineToCover lineNumber="3" covered="true" branchesToCover="8" coveredBranches="7"/>
  </file>
</coverage>

The root node should be named "coverage". Its version attribute should be set to "1".
Insert a "file" element for each file which can be covered by tests. Its "path" attribute can be either absolute or relative to the root of the module.
Inside a "file" element, insert a "lineToCover" for each line which can be covered by unit tests. It can have the following attributes:

  • "lineNumber" (mandatory)
  • "covered" (mandatory): boolean value indicating whether tests actually hit that line
  • "branchesToCover" (optional): number of branches which can be covered
  • "coveredBranches" (optional): number of branches which are actually covered by tests

Unit tests report format

The project for which you want to import unit tests result should contain an XML file complying with the attached XSD schema.
It should look like the following sample:

Code Block
languagexml
<unitTest version="1">
  <file path="src/main/java/com/example/MyClass.java">
    <testCase name="test1" duration="500"/>
    <testCase name="test2" duration="600"/>
    <testCase name="test3" duration="600">
      <failure message="sort message">long stacktrace</failure>
    </testCase>
    <testCase name="test4" duration="600">
      <error message="sort message">long stacktrace</error>
    </testCase>
    <testCase name="test5" duration="600">
      <skipped message="sort message">long stacktrace</skipped>
    </testCase>
  </file>
</unitTest>

The root node should be named "unitTest". Its version attribute should be set to "1".
Insert a "file" element for each file which can be covered by tests. Its "path" attribute can be either absolute or relative to the root of the module.
Inside a "file" element, insert a "testCase" for each line which can be covered by unit tests. It can have the following attributes/children:

  • "testCase" (mandatory)
  • "name" (mandatory): boolean value indicating whether tests actually hit that line
  • "duration (mandatory): long value in milliseconds
  • "failure|error|skipped" (optional): if the test is not ok report the cause with a message and a long description
  • "message" (mandatory): short message describing the cause
  • "stacktrace" (optional): long message containing details about "failure|error|skipped" status

Project configuration

The path to the XML file containing coverage data can be configured in 2 ways:

  • In the SonarQube page of the project: Configuration > Settings > Generic Coverage.
  • By setting one or more of the following properties

    Code Block
    sonar.genericcoverage.reportPaths=report1.xml, report2.xml
    sonar.genericcoverage.itReportPaths=it_report.xml
    sonar.genericcoverage.unitTestReportPaths=ut_report.xml
    

These properties can be a comma separated list of paths either absolute or relative to the root of the module.

Coverage data, integration tests coverage data and unit tests will be imported on the next analysis. If this is not the case, check the analysis logs for warnings.