Generate code coverage report for iOS apps in Jenkins server

Code coverage is a good method to describe the degree to which the source code of a project is tested and how well the project is tested. In iOS develop world, around 25%  test code coverage is common required in business. Unfortunately, iOS native develop IDE (aka Xcode) hasn’t provided a default build-in code coverage feature yet. So here is my solution for it.

1. Install Homebrew

Homebrew is a useful tools manager in OS X, please install it first by copying the following command in your Mac’s Terminal

ruby -e “$(curl -fsSL”

2. Install alcove

There are lots of code coverage generator tools for Mac, but some might be too old for the newest Xcode, I used to use gcovr and Cobertura for code coverage test, but unfortunately it doesn’t work for me in Xcode 6 anymore. Here I prefer alcove, which is based on lcov.

Use the following code to install alcove, an open source code coverage generation tool for mac.

gem install alcove

And do member to follow the link below to configure your iOS project to allow the code generation function.

3. Install lcov

brew install lcov

4. Install HTML Publisher plugin

Go to your Jenkins server settings via “Manage Jenkins”—“Manage Plugins”—“Available”, search for “HTML Publisher plugin” and download it.

5. Setting up an iOS project in Jenkins

For details please check my last post

6. Add an Execute shell in your own Jenkins iOS project setttings

Please go to the project settings, click “Add build step”, and copy the codes below.

# generate the coverage report

mkdir -p ./CodeCoverage

alcove –product-name ${JOB_NAME} –output-directory ./CodeCoverage –remove-filter *.h,main.m,Applications,*/CoreData/_*

P.S. make sure the project name is the same with your iOS project scheme name, otherwise please change the “${JOB_NAME}” to your own product name directly.


7. Add post-build action for reports

Add the “Publish HTML reports” in “post-build action” area, and configure it like below.


8. Save your project settings and click Build Now

If everything goes well, you’ll find the code coverage report in your project main page after successfully running.




Thoughts on “Generate code coverage report for iOS apps in Jenkins server”

  1. I would like to thank you for the efforts you’ve put in penning this site.
    I’m hoping to see the same high-grade content from you in the
    future as well. In truth, your creative writing abilities has inspired me to get
    my very own blog now 😉

  2. Mark Shen Post author

    thx for the information, basically they are the same tool (all based on lcov) so all have the similar features

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to the Weekly Blog Digest:

Sign Up
Follow Us