Ship it Day 3: Setup iOS Unit Testing Framework

Published in Uken Games

I recently got word that our team would be taking over work on the native iOS framework that powers all of the iOS builds for our games. This framework is not too feature packed since the majority of our applications run within a UIWebView wrapper but I was excited at the prospect of doing some native Objective-C work again. In my first co-op term I had worked as an iOS developer and I have several of my own projects out on the app store as well but it has been quite a while since I have done much of anything in that realm.

With all of that primer, I decided that I wanted try my hand at adding a unit testing library to our iOS framework for my third Ship it Day project. All of the Ruby code that we write on the Services team is well tested upfront but all of the native code that we write has thus far not received the same treatment. This seemed like the sort of project that would not be accomplishable in the limited timeframe but I decided the future benefits were too large to pass up.

With the introduction of Xcode 5, unit testing has truly become a first class citizen and many of the issues that were preventing people from writing tests have been addressed. I started off the day by watching the WWDC 2013 session on testing in Xcode 5. A new class called XCTestCase has been introduced to allow you to inject a test runner into your application. This took be quite a while to figure out how to integrate into our project. Out of the box there does not seem to be great support for testing libraries/frameworks. The testing process expects to run your AppDelegate and actually launches the application using the simulator or your attached device. To get around this, I ended up creating a dummy iOS application that would essentially only be available to drive our test suite. It was quite easy to add this application to the workspace using the CocoaPods dependency management system that we are trying to migrate to at Uken.

At demo time, I think I only had around 4 extremely simple tests functioning. I was equally embarrassed at the amount of work I appeared to get accomplished and proud to say that our native iOS framework had an ounce of test coverage. Everyone on the team was very encouraging and certainly saw the merit. You have to start somewhere!