How to run and debug unit tests for an iPhone application How to run and debug unit tests for an iPhone application xcode xcode

How to run and debug unit tests for an iPhone application


This post is intended as a "How-to" more than a real question. Therefore this answer is just meant to allow me to mark the "How-to" as "answered". This will probably be flagged by the community as irregular. I'm up for suggestions on where to post future "How-to" articles.

One final note though on this topic.For those who still wonder whether writing unit tests is worth it I would definitely say Yes!

I am currently writing an application with CoreData and retrieval of data from a web service (xml parsing). The complete model can be tested and debugged without having to:

  1. run the actual application on the simulator or device. Not having to use the device to run the tests is a huge gain of time. It's the difference between 2 minutes and 5 seconds per run.
  2. without the need to create views or controllers when testing the model. The complete development and testing can focus on the model only in the first iteration. Once the model is cleared for integration the rest of the development can follow.

To debug the xml parsing I can simply use "hard-coded" files which I completely control.

The crux is of course to write the tests as you implement features in the code. It really is a time saver down the line in terms of debugging of the complete application.

VoilĂ , I'll leave it at that.


I was able to run the test case in debugger in the following simple steps:

  1. Product > Build For > Testing
  2. Put a break point in part of the test you want to debug
  3. Product > Test

This is on Xcode 6.0.1 and seems much more convenient than the long procedure described above.