Using unit tests in IOS development

by Theo27. April 2012 21:57

Using unit tests in XCode you have the posibility to have two test targets (sub-projects) set up; one for logic tests and one for application tests. So whats the difference?

Logic tests run without the Application running, so you wont be able to reach your app-delegate or anything UI related, but you will be able to test POOC's (Plain Old Obj-C Classes). The Application Tests target, will start up the simulator and use it to run your unit tests.

When i develop, i normally use the logic tests target for the classes providing domain behaviour. Not having to start up the simulator makes theses tests fast to run, making the feedback cycle shorter and you always want as short a feedback cycle as you can get. So when implementing a new feature i start up with the base domain behaviour and make it run with the logic tests. I then i move to the GUI, which uses this new feature and implement it with tests in the Application tests target. With this working i can then wire up the nibs or similar and start up the simulator to check that the feature works as it should.

It did initially seem a bit odd to have two unit test targets, but being that the one needs the simulator to run it makes sense.

Theo Andersen

Hi, you've reached my blog on software development.

I use this blog mostly for my own purpose of remembering stuff, so i only put things here once in a while when i get the time.

My current focus is on TDD, unit testing, object oriented code and IOS development.