Code Coverage Fixed for Xcode 5.1


The Xcode 5.1 update proved to be more exciting than I anticipated. And I mean “exciting” in the sense of “breaking the tools I use.” xctool stopped working, and so did my code coverage scripts.

XcodeCoverage - code coverage for Xcode

Hole by Bart Everson, used under CC BY 2.0 / Cropped original and added logo and title

(Lesson learned: Always download the developer preview and give it a try, before running Software Update…)

Facebook updated xctool. And I’m happy to say that XcodeCoverage now works with Xcode 5.1! Thanks to my coworker Mike Maietta for figuring out how to create a wrapper around the new gcov so that it continues to work with lcov.

Your coverage numbers may change slightly as you use Xcode 5.1 — but not much. And we don’t need the __gcov_flush() workaround anymore. Hurrah!

Bonus: “Generate code coverage report?” prompt

Finally, I incorporated a submission by Matthew Purland which gives you a way to have XcodeCoverage ask whether you want code coverage whenever you run unit tests. If you want to give a try, edit your Xcode scheme and spin down Test to show Post-actions. Add a New Run Script Action, then do the following:

  • Set “Shell” to /bin/bash
  • Set “Provide build settings from” to your main target (in the example below, I’m doing this for OCHamcrest)
  • Set the script to source ${SRCROOT}/XcodeCoverage/

Post-actions to get code coverage after unit tests

Once you do that, run your unit tests. Once they complete, you should see this prompt:

Generate code coverage report?

Click OK, and XcodeCoverage will run for a while, then show you the coverage results. Pretty slick. (Of course, don’t add this optional step to any shared schemes used in automation.)

…Again, go get the latest XcodeCoverage to get up & running again on Xcode 5.1. Enjoy!

About the Author Jon Reid

Jon is a coach and consultant on iOS Clean Code (Test Driven Development, unit testing, refactoring, design). He's been practicing TDD since 2001. You can learn more about his background, or see what services he can bring to your organization.

follow me on:

Leave a Comment:

Add Your Reply