Saturday, February 19, 2011


How to debug XCode Unit Tests?

XCode has the necessary facilities (based on OCUnit) to easily create and execute unit tests. No doubt I want to take advantage on test driven development when developing iPhone and iPad Apps. There are two different kinds of unit tests according to Apple's documentation namely Logic tests (Unit tests in the pure sense) and Application tests (they are more to be considered system level tests).
How to set up each kind of tests for your project is documented in Apple's iOS Development Guide
Logic Tests will be executed at compile time when the target is Simulator. Application tests on the other hand will be executed when you "Build&Run" your code on the device. Sooner or later there will be the need to debug your tests. Debugging Application tests is just a matter of setting break points and "Build&Debug". Debugging Logic tests is not as easy though. There is a good description on how to get it to work anyway see How to debug iPhone Unit tests
I followed the steps mentioned in this blog post but alas it didn't work. :( So I fiddled a bit until I found the solution. Basically all the steps mentioned are correct and I'm happy I didn't had to find them myself (so a big thanks to the author!). The only thing that was incorrect were the necessary environment variables as described in section "Setting up the otest Environment". According to my investigations no only were most of them needless (at least with XCode 3.2.5 and iOS SDK 4.2) some of them turned out to be counter productive (*). To make a long story short the only environment variable that need to be set is DYLD_ROOT_PATH=$SDKROOT and you can happily debug your Logic Tests.

(*) In case you are interested: I found out which of the environment variables were problematic by setting the DYLD_PRINT_ENV environment variable (see 'man dyld') and have the dynamic linker print his environment. This way I saw that some of the paths (especially those containing spaces ;)) were incorrectly quoted.

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?