Why doesn't gcov report any lines being covered by my unit tests? Why doesn't gcov report any lines being covered by my unit tests? xcode xcode

Why doesn't gcov report any lines being covered by my unit tests?


I have been running into this problem intermittently. I stumbled into a good length of lucky time where it was "mostly working" in my main project. By mostly working I mean I was able to get coverage to show up, but with a little more pain than on 10.5. I had to aggressively delete the coverage files and rebuild in order to get any updates, for instance. Even in my "barely working" state, the compiler/runtime doesn't seem willing to overwrite an existing coverage data file.

I think I've stumbled back on to a working scenario. Voodoo for sure, and less than ideal:

  1. Make sure the SDK is 10.6.
  2. Make sure the deployment is set to gcc 4.0 (!).
  3. Do a full clean of the project.
  4. Rebuild.

Does this get you the expected coverage data?

Granted, I would expect to be able to generate coverage files that work using gcc 4.2 or one of the LLVM compilers, but for the moment this seems to have me slightly less crippled than before.

Another clue: when I observe the coverage data (using Google's Cover Story), I get warnings like:

/BUILDRESULTS/MarsEdit.build/Code Coverage/MarsEditDataModelTests.build/Objects-normal/i386/MEDataItem.gcno:version '400A', prefer '402*'

But the coverage information is still presented. So it seems it's balking at an older coverage format version, but if I use the newer compiler (4.2) which would presumably generate the newer format .gcno files, the 0% coverage problem plagues me as it does Graham.


In Xcode 4.6, coverage reports just seem to work. Turn on "Generate Test Coverage Files" and "Instrument Program Flow" for the app target, run the tests, then point the coverage tool at the output. That's in ~/Library/Developer/Xcode/Derived Data/<Project>-<hash>/Build/Intermediates/<Target>.build/Debug-iphonesimulator/<Target>.build; opening that folder in CoverStory shows me the results I expected.

This GitHub repository contains scripts that can automatically discover the output and get lcov to visualise it; I'm happy with CoverStory for now.


You can get code coverage working with gcc 4.2.1. Details here:

SnowLeopardGCov