Wednesday, June 17, 2015

Objective-C: Travis-CI and Coveralls.io (2/2)

Until now we've added to our repository just the support for Travis-CI. Now it's time for Coveralls.io which is basically the second part of this Pull Request.

Coveralls is a service that analyses your code and gives a percentage of code that is covered by some tests.

Coveralls.io

If your code is already on Github, you can navigate now to Coveralls.io and activate the support for your repository, otherwise you can do it at the end, but then the next commit will show up on Coveralls.io. As we already had for the Travis-CI;

1) This service will start after Travis-CI so he needed to invoke it when Travis-CI has finished. This can be done by adding it to the .travis.yml
after_success: bundle exec slather
As you may already expect he had to include slather into our Gemfile and execute it
source 'https://rubygems.org'
gem 'cocoapods'
gem 'rake'
gem 'slather'
gem 'xcpretty'
Slather, as Travis-CI needs its own configuration file which is .slather.yml in this case

2) If you'd run now the bundle exec slather command you'll probably end up with an error as Xcode is not generating coverage files if they are not needed. There are basically two flags to set in the xcodeproject file
  • GCC_GENERATE_TEST_COVERAGE_FILES = YES
  • GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES
Basically there are the methods to set these flags

  1. Open Xcode, search in Build settings for Instrument Program Flow and Generate Test Coverage Files and set both of them to YES which will generate the needed files on every build
  2. You can do the same executing the command $ slather setup path/to/project.xcodeproj which will automatically set those flags
  3. Add the parameters to the build command in the Rakefile which will generate them only when you execute the rake build.

3) Now as in Travis-CI just add the badge to the readme
[![Coverage Status](https://coveralls.io/repos/hons82/THSegmentedPager/badge.svg)](https://coveralls.io/r/hons82/THSegmentedPager)

No comments: