Search code examples
iphoneunit-testingxcode4code-coveragellvm

How do I get code coverage for tests and build for iPhone in Xcode 4?


I have a couple of projects with unit tests where I want to measure coverage. So I follow the instructions detailed in the How-to for CoverStory and elsewhere on the web.

I add -fprofile-arcs and -ftest-coverage to my test target and the target under test and link to /Developer/usr/lib/libprofile_rt.dylib as specified.

And it works! When I run the tests scheme under the iPhone simulator, I get my code coverage, my tests and app build and run.

But then, when I go back to the Run scheme on actual iPhone hardware, I get a link error for libprofile_rt.dylib. Specifically, I get

ld: library not found for -lprofile_rt

What I suspect here is that libprofile_rt is actually a library for Mac hardware and the iPhone obviously can't link to a binary built for Mac, in general.

My question is How do run on iPhone hardware and get my code coverage?

I suspect I can do this with a copy of my Debug target that is only ever used for testing, but that has the additional trouble of maintaining yet another target. Is there any other way to get this working? Am I doing something silly?


Solution

  • might a little bit late but actually you can. it is explained in this presentation, slides 32 to 34.

    took me a fair amount of time to find this hidden gem. hope this might help future visitor of this page.