Run Kiwi tests from the command line with XCode 4.6

Apr 22, 2013 • Running your tests from command line is the first step to make continuous integration on your Xcode projects.

Just finished this article when Apple has released a major update, I’ve named XCode 5.0, so soon an updated article on how to achieve the same task under the new version of Xcode !

At first, I made some research on my favorite search engine, unfortunately none of the resources I found talked about running test suits for a project that was using CocoaPods.

The first article very interesting – but outdated – is Running OCUnit & Kiwi Tests on the Command Line by Stewart Gleadow. It helped me a lot to understand where to look, but since his article XCode has been updated and the private script that he was hacking has been changed… that is no longer a viable solution.

That’s why I thought about writing a new fresh article.

Configure your XCode schemes

First duplicate your main scheme. And let’s call this duplicated scheme CommandLineUnitTests.

You need to activate the Run checkbox for the CommandLineUnitTests scheme

Here is a Makefile that you can use. It takes care of various things :

test:
    osascript -e 'tell app "iPhone Simulator" to quit'
    xcodebuild -workspace Example/Example.xcworkspace -scheme CommandLineUnitTests -sdk iphonesimulator6.1 -configuration Debug ONLY_ACTIVE_ARCH=NO TEST_AFTER_BUILD=YES RUN_APPLICATION_TESTS_WITH_IOS_SIM=YES
  • first thing to do is to shutdown the iPhone simulator, otherwise it can fail
  • ONLY_ACTIVE_ARCH tells Xcode to build for all architectures and not only for the one active
  • TEST_AFTER_BUILD no need to tell you about this one I guess
  • RUN_APPLICATION_TESTS_WITH_IOS_SIM pretty straight forward too

Real world example

I’ve integrate the whole thing into a project of mine, DPMeterView hosted on GitHub, and the project is integrated with Travis Continuition Integration servers. Learn more on how to integrate Travis-CI in your open source iOS project, to build stronger libraries!

comments powered by Disqus