Exporting code coverage results in SonarQube format
You can export code coverage results in SonarQube format.
Procedure
Results
When the result exporting is done, you can find the exported files in SonarQube format in the destination folder that you specify.
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 as below.Root/coverageReport.xml
/sonar-project.properties
/src/... coverageReport.xmlis 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.propertiesis 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
ICCExporterSettingscontains methodssetPropertyandgetProperty. 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.sourcesequals to thesrcfolder andsonar.coverageReportPathsequals 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
srcis the folder that contains source files, listings, or both.