Exporting code coverage results in SonarQube format
SonarQube is a format that can be imported into a SonarQube server.
Procedure
Results
When the result exporting is done, you can find the exported files in SonarQube format in the result location that you specified.
The exported files in SonarQube format include a
.xml
file of coverage report, a
.properties
file that contains SonarQube Scanner settings, and the source code that
matches the report. For example, you can find a typical output folder structure for the exported
results in SonarQube format.Root/coverageReport.xml
/sonar-project.properties
/src/...
coverageReport.xml
is an xml file in generic SonarQube coverage report format, which contains information about covered lines. The file name can be chosen arbitrarily, as one of the arguments for exportResult method.sonar-project.properties
is the configuration file for SonarQube Scanner. CCSonarQubeExporter prints the default and user-defined properties that are required to this file to import the coverage data into SonarQube:- As one of the parameters to exportResult method, an instance of
ICCExporterSettings
contains methodssetProperty
andgetProperty
. Most of the SonarQube properties have the prefixsonar.
and the exporter writes any properties that have this prefix into the file. - Certain properties have their reasonable default value, or the value can be guessed with the
other given data that is provided to the exporter. For example,
sonar.sources
equals to thesrc
folder andsonar.coverageReportPaths
equals to the coverage report file name. These key-value pairs appear in the file as well. - Some properties are required by SonarQube, such as
sonar.projectKey
. If no value is provided in theICCExporterSettings
, the exporter still prints out such keys with no value but the lines are commented out as follows:
You can edit the file later to define any missing properties or to provide these values as command-line arguments for SonarQube Scanner.#sonar.projectKey=
- As one of the parameters to exportResult method, an instance of
src
is the folder that contains source files, listings, or both.