SonarSwift is able to import coverage reports generated by Xcode using two approaches: relying on the Generic Test Data format or based on .profdata file.
For Xcode 9.3+ : Rely on the "Generic Test Data"
SonarQube supports a generic coverage format allowing to load any coverage report as soon as you find a way to convert a native coverage format to the SonarQube's format.
Xcode 9.3 introduced a tool called
xccov that lets you obtain coverage data per file. You can then convert this data into the SonarQube Generic format, and load it thanks to the property sonar.coverageReportPaths (see documentation).
The xccov-to-sonarqube-generic.sh script uses the following xccov commands to convert the Xcode format into SonarQube's format:
list all the files potentially having coverage data:
for each file, get the coverage details:
For Xcode 7 - 9.2 : Rely on .profdata
Prior to the SonarQube analysis, execute your unit tests and generate the coverage report.
Note that the scheme you use to build the project should have coverage enabled. The "xcodebuild" command for your project might require more parameters than in the example below.
Import this report while running the SonarQube analysis by providing the path to the coverage report through the following property. Note that coverage report generation and SonarQube analysis should be performed on the same machine, since coverage reports contain absolute paths.
Path of the coverage report generated from \"llvm-cov show\". This path can be either absolute or relative to the project directory.
A sample project can be downloaded here: https://github.com/SonarSource/sonar-scanning-examples/tree/master/swift-coverage