XCode 13 Not reporting accurate test Covarage

Following moving to Xcode 13 from 12.5, we are seeing our test coverage reported at ~1%, with only a small number of tests being reported in line with previous xcode builds.

Is this a know issue? Are there steps we can take to debug or mitigate this?

Nothing of note identified within the build log.

Xcode 13 Coverage:

Xcode 12 Coverage:

  • Hi, Are you able to fix this issue? same we are facing in Xcode 13.1

  • Hey, unfortunately we had to create a new project in order to do so.

  • Hi, Are you able to fix this issue? We get a similar issue in Xcode. 13.3 which the code coverage is 0 but Xcode 12.5 is fine.

Add a Comment

Replies

We are seeing the exact same issue in our projects, and I havn't found a solution/fix nor a reason yet. Just wanted to share so you know you are not the only ones in this situation.

  • Hey Morten, Thanks for the response. Not sure what you have tried. So far I have tried deleting and re-introducing test plans with no luck. Aside from that I'm unsure as to what steps we can take.

    I've also noticed that on other application/projects it's all reporting as expected.

    It's a strange one. Welcoming any suggestions.

  • Our coverage report ist gone completely. Build log shows the following line:

    Failed to merge raw profiles in directory /Users/<…>/Library/Developer/Xcode/DerivedData/<…> to destination /Users/<…>/Library/Developer/Xcode/DerivedData/<…>/Coverage.profdata: Aggregation tool /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/llvm-profdata failed with exit code 1

  • We are also getting a very similar warning to the one posted by @COPAtec. In our case it seems to have a different file name though.

    Failed to merge raw profiles in directory /Users/<user>/Library/Developer/Xcode/DerivedData/<project>/Build/ProfileData/<UUID> to destination /Users/<user>/Library/Developer/Xcode/DerivedData/<project>/Build/ProfileData/<UUID>/CoverageAggregate1.profdata: Aggregation tool '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/llvm-profdata' failed with exit code 1

We also see similar problems with generating coverage data (Xcode 13.1):

Failed to merge raw profiles in directory /Users/j<user>/Library/Developer/Xcode/DerivedData/XYZ-aoivlaczsouiakebozusuojanhvg/Build/ProfileData/<UUID> to destination /Users/<user>/Library/Developer/Xcode/DerivedData/XYZ-aoivlaczsouiakebozusuojanhvg/Build/ProfileData/<UUID>/Coverage.profdata: Aggregation tool '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/llvm-profdata' failed with exit code 1

  • This is also still present for me on Xcode 13.2.1

Add a Comment

We have been waiting for new Xcode 13.x releases, but the problem is still here with Xcode 13.2.1.

I have tried to create a new dummy-project from scratch, and that project reports coverage correct in Xcode 13.2.1. I have tried to look through buildsettings in the dummy-project compared with the real projects we have, where coverage is not reported correct. But I have not been able to find the magic setting that is causing the failure of coverage.

It would be nice if an Apple Engineer can shed some light on what settings to try to change, or maybe throw in other ideas on what to try to provide some useful logging (besides the errors already shared in here that seems to point to the Aggregation tool). Since a new project from scratch seems to work fine, it's not possible to upload a small sample project to demo the problem.

  • Hi, Are you able to fix this issue? same we are facing in Xcode 13.1

Add a Comment

In the release notes for Xcode 13.3 beta theres an interesting entry:

Xcode now collects code coverage data for processes that crash while running tests. (58496759)

Maybe this solves the issues (or some of them).

  • Just upgraded to 13.3 but sadly this still seems to be an issue

Add a Comment

We're facing the exact same issue with Xcode 13.3 on Apple Silicon Mac. It seems to be fine on Intel Mac though.

  • UPDATE: The same issue happens on Intel Mac as well. For us, the issue would only happen when running tests on a real device (e.g. iPad), not on iOS simulators.

  • Xcode 14 beta no longer has the issue for our case.

Add a Comment

Disabling the code coverage for the pod repos inside pod project resolved this issue.

Add bellow script in Podfile to disable the code coverge

config.build_settings['CLANG_ENABLE_CODE_COVERAGE'] = 'NO'

config.build_settings['swiftc'] = '$(SRCROOT)/SWIFT_EXEC-no-coverage'

Tried the script above, it didn't work.

My solution: If you have flag "GCC_GENERATE_TEST_COVERAGE_FILES=YES" specified in xcodebuild arguments, remove it in XCode 13. It seems like this will extract coverage data out of "*.xcresult" files in xcode 13.

  • Your hint saved my life. I need to clean two Build Settings in my test target to No Instrument Program Flow & Generate Legacy Test Coverage Files

  • Setting No value to Instrument Program Flow & Generate Legacy Test Coverage Files helps to solve the problem. Thanks!

Add a Comment

We were able to find the root cause.

In our case, we were using 3rd party library (using Cocoapods). We changed the Mach-O type for that pod (inside the Pods.xcodeproj) to Static Library and the code coverage started working. By default, it was a Dynamic Library.