Setting up Code Coverage Report for Swift iOS application

  • Repos in Azure Repos
  • CI system used Azure DevOps
  • Languages of the repository - iOS apps using Swift

SonarQube used to work before Xcode 11, now Xcode 13 is being used and Sonar reports are not getting generated.

I am looking for a well guided article for best practices in iOS code coverage setup.
Xcode Test is passed with below args and is generating xcresult file.
-derivedDataPath Build/ -enableCodeCoverage YES -resultBundlePath Build/Logs/Test/Test/

Previous setup utilized a bash to process the xcresult and generate sonar coverage file. This is failing.
Internet search and solutions dont seem to be working.

 2022-04-26T14:57:03.4247960Z Error: Error Domain=XCCovErrorDomain Code=0 "Failed to create unarchiver" UserInfo={NSLocalizedDescription=Failed to create unarchiver, NSUnderlyingError=0x7fdc73c47370 {Error Domain=NSCocoaErrorDomain Code=260 "The file “Metadata.plist” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/Users/runner/work/1/s/tmp.xccovarchive/Metadata.plist, NSUnderlyingError=0x7fdc73c472b0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}}}
2022-04-26T14:57:03.4455370Z ##[error]Bash exited with code '1'.
2022-04-26T14:57:03.4479240Z ##[section]Finishing: Bash Script

Since it is running on a hosted build agent, files cant be retained for debug it seems.

Has anyone found a workable solution for iOS apps with a similar approach.


what is this error logs you have posted? Is it from running bash script? which script exactly?

Do you have similar line among the logs? line 68: jq: command not found

If so, you should install jq on the machine where you generate the coverage report.

Hi Elena, thanks for responding.
This is the output of the file you have mentioned.
The output is from an Azure DevOps hosted MacOS agent that already has JQ installed as per their documentation(also no similar line for jq not being present).

I do see there is a metadata.db in a different folder, not sure if that is relevant to this script.

2022-05-03T06:00:15.9747660Z /Users/runner/work/1/s/Build
2022-05-03T06:00:15.9748040Z /Users/runner/work/1/s/Build/TestResults
2022-05-03T06:00:15.9748460Z /Users/runner/work/1/s/Build/TestResults/metadata.db
2022-05-03T06:00:15.9748850Z /Users/runner/work/1/s/Build/Logs
2022-05-03T06:00:15.9749240Z /Users/runner/work/1/s/Build/Logs/Test
2022-05-03T06:00:15.9749620Z /Users/runner/work/1/s/Build/Logs/Test/Test
2022-05-03T06:00:15.9750070Z /Users/runner/work/1/s/Build/Logs/Test/LogStoreManifest.plist
2022-05-03T06:00:15.9750530Z /Users/runner/work/1/s/Build/Logs/Test/Test.xcresult
2022-05-03T06:00:15.9751220Z /Users/runner/work/1/s/Build/Logs/Test/Test.xcresult/Data

This seems to be due to some fishy package R.Swift used in the project that coverage data is not getting generated. Will post once we have the problem fixed. Nothing related to Sonar as of now.

1 Like

I’m using Fastlane and Slather to generate generic coverage report and put its path to