SonarQube - * Enterprise Edition * Version 9.3 (build 51899)
Scanner - SonarQube Scanner 22.214.171.12447
Xcode Version 13.2 (13C90)
Apple LLVM version 13.0.0 (clang-1300.0.29.30)
We are generating a coverage report like so
- swift test --enable-code-coverage
- xcrun llvm-cov show
which results in a
Sonar/coverage/…/… contains the directory structure with single source file coverage data
in sonar-project.properties we have configured
The following are also configured (details partially left out)
After running sonar-scanner with the specified parameter
the jobs run successfully and we see all the files from the coverage directory but the overall coverage is reported 0% in the single source files all covered lines are marked red in SonarQube.
Do we miss something here?
sonar.swift.coverage.reportPath is the correct analysis parameter, rather than
sonar.swift.coverage.reportPaths (note the final
s isn’t present in the correct parameter). You’ll find the correct analysis parameter also documented here
Please note that these analysis parameters don’t have any effect (they’re either removed, or come from the community supported GitHub - Idean/sonar-swift: Open source Swift plugin for SonarQube (also supports Objective-C))
Corrected the path parameter and run the job again. Here’s the result for the swift path.
INFO: Sensor Swift Code Quality and Security [swift]
INFO: 47 source files to be analyzed
INFO: 47/47 source files have been analyzed
WARN: Property ‘sonar.swift.coverage.reportPath’ is deprecated and will be soon ignored, use ‘sonar.swift.coverage.reportPaths’ instead.
INFO: Parse coverage report (Sonar/index.txt)
INFO: Sensor Swift Code Quality and Security [swift] (done) | time=2060ms
Something I noticed is that Coverage for a single file is shown with a red bar on the lines, which are covered by unit tests.
@Colin Could you comment?
It is somehow disappointing that getting coverage data in Sonarqube for iOS projects is such a pain.
Is it really not working?
SonarCloud (currently on 9.5)
Xcode: 13.4.1 with Swift 5.6
Apple LLVM version 13.1.6 (clang-13126.96.36.199.5)
I have run into this problem myself. Our project builds a swift package and we’re not using
xcodebuild to build and run tests. The following works for us, note I am using
sonar.swift.coverage.reportPaths option, Previously suggested option
sonar.swift.coverage.reportPath is deprecated and I get a warning during the scan not to use it.
Build and run tests:
swift test --enable-code-coverage
Generate coverage report and save to a file:
xcrun llvm-cov show -instr-profile=.build/debug/codecov/default.profdata .build/debug/MyPackageTests.xctest/Contents/MacOS/MyPackageTests > coverage.report
Run the scan:
xcrun llvm-cov show
Removing --output_dir option helped to get the coverage report.