iPhone SDK and OCUnit

by Dana H. P'Simer

Sun, Mar 9, 2008


I have started fooling around with the iPhone SDK. I am planning to release a product soon but the plans are quite preliminary so mums the word on exactly what is coming. However, I ran into a little problem right off the bat.

I am a Java Developer. I am trying to add iPhone/Mac OS X development to my skill set. But given my strong Java background I have an absolute commitment to unit testing. It is extremely important that you construct unit tests for your code. As such, I immediately went looking for tools to help me do just that.

It seems that the iPhone SDK projects are not setup to be compatible with OCUnit out of the box. In this, Test Driving Your Code with OCUnit, article at developer.apple.com you are told to simply:

  1. create a new "Cocoa > Test Framework" target. Actually, under the newest XCode it is called "Cocoa > Unit Test Bundle"
  2. Add the "SenTestingKit" Framework to that target. You will need to look for this in "/Developer/Library/Frameworks" (assuming you installed XCode into /Developer) instead of the default "/System/Library/Frameworks".
  3. Create a group for test cases

I did these things and it still did not work. The first error I got was in regards to the “Cocoa.h” not compiling. This is because the target I created used the project’s “Base SDK” which is the “Device - Aspen 1.2” so I changed it to “Mac OS X 10.5”. As such, you cannot compile source that includes “UIKit.h” with this SDK. So, for now, I guess unit testing will have to be confined to classes that do not depend directly on UIKit.

The next error I got was because the default compiler dialect is set to C99, This should be changed to GNU99. I found this answer in this article: Stupid Issue with OCUnit.