Show Test Coverage in Xcode
There is CoverStory - an open source utility that can show you test coverage for your XCode unit tests.
The problem is that CoverStory requires you to pick correct directory where object files and coverage metrics are stored. The directory could change from time to time.
If you add this osascript as post test action in your scheme the CoverStory will open automatically.
To do that select Product->Edit Scheme in Xcode menu. When the drawer opens expand Test and select Post-actions. Click on (+) and pick “New Run Script Action” from the drop-down.
Set Shell to
1 |
/usr/bin/osascript |
Set “Provide your build settings from:” drop-down to your test bundle, which is called Unit Specs in our case.
And copy and paste this code:
Here is the screenshot (click to enlarge):
To enable test coverage measurements in your project, you have to set the following build Settings on your test target:
1 2 3 |
GCC_GENERATE_TEST_COVERAGE_FILES = YES
GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES |
If your Xcode test target fails with the following error:
1 2 3 |
Detected an attempt to call a symbol in system libraries that is not present on the iPhone:
fopen$UNIX2003 called from function llvm_gcda_start_file in image ... |
Then you can add this workaround for missing symbol:
Try it out, let us know how it worked for you.
One Comment
Sweet addition. Now I don’t have to indicate each time the directory =)