简体   繁体   中英

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?

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.

The answer is: you can't run on your device AND get coverage at the same time. The only way to get coverage is on the simulator: make a copy of your debug target, setup coverage and what not on that target and run that target, with your tests, in the simulator.

I go through all the details in an answer to this question on stackoverflow: Code coverage on iOS Using Xcode 4.2 on Lion

Possible answer to this problem is here: https://stackoverflow.com/a/5140459

The trick is to get the *.gcda files out of the App's Documents directory via Xcode organizer, since they will, of course, be generated on device.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM