Thanks for being a part of WWDC25!

How did we do? We’d love to know your thoughts on this year’s conference. Take the survey here

Code Coverage not showing properly?

I have an old Xcode project that I am adding tests to, and at a high level I see the code coverage percent (the 2.2% number). However, in the detail view, code coverage only shows on the testing bundle, not in the main app bundle.

Anyone have any tips on how to fix this?

A few things to check:

  1. Does your test code actually call into your application's code? Kind of obvious, but should be verified.
  2. In your test plan settings for Code Coverage, is it "On" for all targets or just for some targets?

There could always be a bug here, but investigating it might require access to the project.

Yeah the tests call into the application code and all the tests pass. And I verified the settings have code coverage on.

The issue is that the project is so old, I feel like something is conflicting in the settings? I was very confused by the different settings that seem to affect code coverage (the scheme settings both when using test plans and when not, CLANG_ENABLE_CODE_COVERAGE, GCC_GENERATE_TEST_COVERAGE_FILES etc)

But I hear you, it might just too complex to debug in the abstract. I was hoping there would be an easy solution, cause the tests do run, and I am seeing 'number go up' as I add tests. I just don't have access to file-based coverage. It seems to be just overall coverage stats (based on the image in the post).

Accepted Answer

Just wanted to come back here in case my solution helps others.

As I mentioned, the project in question is very old (prob 10 years at this point). I have updated it over the years, but....yeah.

To start I created a brand new Xcode project with Xcode 16.3. Then I opened my old project and the new project, showing the build settings in 'Levels' view, so I could see each setting and where it is modified. I meticulously went thru each setting comparing my old project to the new project and changed my old project to match the new project (where it made sense, for example, I can't use script sandboxing).

After going thru this process. My coverage works!!!!!

I am not 100% exactly which setting it was, but I noticed that several of setting differences were quite suspicious. Stuff like the C/C++ language dialects being different? The 'Active Compilation Conditions', 'Compilation Mode' and 'Optimization Level'....all were different.

As I said, not sure which setting it was exactly. But to anyone having issues. I recommend this as a process. Just got to buckle down and go setting by setting till you find the magic one!

-pj

Code Coverage not showing properly?
 
 
Q