Running iOS tests on Travis CI

Why

Did you ever ship buggy code in production ? If it is the case, you may consider setting up a CI server.

What

CI stands for continuous integration. CI Server is a machine that watches your main branch and runs your tests every time there are new commits. It ensures that you product is ready to ship from your main branch at any point in time.

How

Setting up and especially maintaining a CI server is pain in the neck. That’s why I prefer to use a CI service instead of hosting a server in house. They scale it, they maintain it, all I do is focus on development.

Setup

Note: The following tutorial works for Cedar testing framework as well as XCTest. Tests should be set up as a test target (not a separate app).

  1. Sign up for an account with Travis CI.
  • Sign up here for a free account if your project is Open Source and it’s public.
  • Sign up here is your project is private.
  1. Enable the app.

Sign into your account on Travis CI. Click on your profile on the top right and choose accounts. Choose the repo that you want to test and flip the switch to on.

  1. Make sure that your scheme is shared.

Open up your project in XCode. Go to Product->Scheme->Manage Schemes. Select the Target that you use for testing and check the Shared checkbox.

Shared scheme in Xcode

  1. Create .travis.yml file

.travis.yml is the configuration file for your build on Travis CI. Here is the minimal .travis.yml file.  Replace MyAwesomeApp with your app name and save it in the root of your project.

language: objective-c
xcode_workspace: MyAwesomeApp.xcworkspace # if you're using cocoapods
# xcode_project: MyAwesomeApp.xcproject #if you're not using cocoapods
xcode_scheme: MyAwesomeApp
xcode_sdk: iphonesimulator7.1
script: xcodebuild -workspace MyAwesomeApp.xcworkspace -scheme MyAwesomeApp -sdk iphonesimulator7.1 -configuration Debug build test
  1. Commit everything, push it up to github and check out you triggered build.

Cheers,

Alex