Automating unit tests in XCode

I’m currently working on an iOS project.  Within the project we have a set of application unit tests.  We are using the Jenkins CI service to automate builds of our product.  We have written a build script, which Jenkins runs once it has checked out our code.  As part of the shell script, we would like to run the unit tests in the project as well, to make sure that the commit hasn’t broken anything.
The steps we have followed to achieve this are based on this excellent blog post:

By adding this line to our build script:

xcodebuild -target unitTestBundleTargetName -configuration Debug -sdk iphonesimulator5.1 TEST_AFTER_BUILD=YES clean build

and patching the /Developer/Platforms/iPhoneSimulator.platform/Developer/Tools/RunPlatformUnitTests file as described in the blog post above, we are able to run our unit tests.

That’s not quite it though.  We’ve updated to use XCode 4.5, which now includes the simulator for iOS6.  There are problems with iphonesimulator6.0.  If you update the line above to use iphonesimulator6.0, you will get the following error:

Unknown Device Type. Using UIUserInterfaceIdiomPhone based on screen size
Terminating since there is no workspace.

This isn’t a problem for us, as we’re not using iOS 6 features. However, if you are, and you need to run the iphonesimulator6.0, then I can imagine this will be a major issue.

I’m going to have a little rant at this point.  It is just good practice to use a continuous integration environment to produce your builds.  One of the prerequisites for this is being able to run and test your builds from the command line.  XCodebuild gets you some of the way, in that it will create a build for you, but it feels wrong that developers are having to patch the Apple developer tools in order to be able to run their unit tests from the command line.  And even if they do, they are not currently able to test iOS6-specific features.

XCode is a powerful tool, but it feels like Apple should be doing more to support good practice like continuous integration.  Coming from a Java background, where this kind of thing is well supported, it is surprising that it is not so in the iOS world.


One thought on “Automating unit tests in XCode

  1. While I certainly agree that Xcode is a powerful tool (and Apple is a great company :-), I *STRONGLY* support the above rant (I get the same error messages) about how Apple [should be] doing more to support good development practice, *ESPECIALLY* since their computers now run a solid operating system (OSX).

    And let me add one … I use emacs (20+yrs). A lot of developers do. However, I can only run command line Xcode (4.6x) applications using gud (emacs’ debugger system). Virtually every other debugger I use is fully supported in emacs, including (of course) gdb,cdb, and jdb.

    I’d like to see lldb suppport *at a minimum*.

    Maybe Apple’s core developers know how to set up emacs to use gud with obj-c/c++ for iOS simulator/iOS/etc., but I’ve Googled and Googled, and hacked and hacked, and still have not been able to solve it (please contact me if you know how to *really* do it). I have my actual job to do, and, so, cannot spend infinite time on this.

    Apple is a plenty big enough company to have strong mainstream development support, including commitment to major industry development environments such as emacs.

    Hopefully Apple’s support for proven, tried and true industry development tools and functionality will not be to let them go the way of (remember?), say, MPW (one of the best IDEs ever IMHO).

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s