I’m using the Google Toolbox for Mac extensions to unit test my iPhone application. I highly recommend them. Integration with XCode is great. E.g. failing assertions in the tests are flagged directly in the code just like compile-time errors right next to the failing assertion. (If you are working on SDK 3.0 beta, you should get this patch to avoid the “-[UIApplication terminate]: unrecognized selector sent to instance” exception when the unit test application quits. terminate was replaced with terminateWithSuccess ins SKD 3.0).

If you want to check the coverage of you tests here is was you have to do:coverstory

  1. Get CoverStory to display coverage information in the code
  2. Setup the build setting in your target to link against gcov (add -lgcov to “Other Linker Flags”) and check “Instrument Program Flow” and “Generate Test Coverage Files” in the “GCC 4.2 – Code Generation” section.
    Goggle also has a script to do that for you - here.
  3. And (here comes the tricky bit ;-) tell the GTM RunIPhoneUnitTest.sh script not to delete the *.gcda files by clearing the GTM_REMOVE_GCOV_DATA environment variable before running the script.

In the end you get the typical coverage information both shown as percentages per file and also as coloring of the lines in the source code.

4 Comments »

  • Appreciate the quick note on this.

    Have you got this to work on Snow Leopard? I have to choose the files individually instead of just a specific folder.

    Comment by Erril — April 20, 2010 @ 3:05 pm
  • Sorry, I have upgraded to Snow Leopard but currently I am mostly working on UI and haven’t looked at my coverage, yet. The one time I tried I had the same problem, though

    Comment by Chris — April 26, 2010 @ 10:01 am
  • The opening folder on Snow Leopard bug is now fixed in the latest version (if you haven’t got a prompt to update yet).

    Also, you may want to look here

    http://code.google.com/p/google-toolbox-for-mac/wiki/SnowLeopardGCov

    for info on doing code coverage on Snow Leopard.

    Comment by dmaclach — June 10, 2010 @ 3:31 am
  • Thanks dmaclach for the pointer

    Comment by Chris — June 10, 2010 @ 11:35 am

Email this Share this on Facebook Share this on LinkedIn Tweet This! RSS feed for comments on this post. TrackBack URL

Leave a comment