Code coverage for Xcode projects
Pull request Compare This branch is 109 commits behind jonreid:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

These scripts provide a simple way to generate HTML reports of the code coverage of your Xcode 4.5 project. For a detailed blog post, see


  1. Fork this repository; you're probably going to want to make your own modifications.
  2. Place the XcodeCoverage folder in the same folder as your Xcode project.
  3. Dowload lcov-1.10. Place the lcov-1.10 folder inside the XcodeCoverage folder.
  4. Get Xcode's coverage instrumentation by going to Xcode Preferences, into Downloads, and installing Command Line Tools.
  5. In your Xcode project, enable these two build settings at the project level for your Debug configuration only:
    • Instrument Program Flow
    • Generate Test Coverage Files
  6. In your main target, add a Run Script build phase to execute XcodeCoverage/

A few people have been tripped up by the last step: Make sure you add the script to your main target (your app or library), not your test target.


  1. Run your unit tests
  2. In Terminal, cd to your project's XcodeCoverage folder, then

    $ ./getcov

If you make changes to your test code without changing the production code and want a clean slate, use the cleancov script:

$ ./cleancov

If you make changes to your production code, you should clear out all build artifacts before measuring code coverage again. "Clean Build Folder" by holding down the Option key in Xcode's "Product" menu.


There are two places you may want to modify:

  1. In, LCOV_INFO determines the name shown in the report.
  2. In getcov, edit exclude_data() to specify which files to exclude, for example, third-party libraries.

More resources