Tuesday, May 5, 2009

OCUnit: Integrated Unit Testing In Xcode

Kailoa Kadano posted a good article on Mobile Orchard showing how to write unit tests for iPhone projects using the built in version of OCUnit in Xcode. This wasn't originally supported in the iPhone SDK, but Apple quietly enabled this in iPhone SDK 2.2.

Kailoa's article shows you the steps to get a unit test target up and running. While it requires a couple of manual changes to the build settings, it's nearly identical to using OCUnit with plain old Cocoa. One gotcha I found was that you must build your application with Active SDK 2.2 or later -- the unit test target will fail when built for earlier iPhone OS versions. Given that the number of users still on 2.0 or 2.1 is probably very small at this point, and sure to get smaller when 3.0 is released, this isn't that bad of a limitation.

I had previously used Google Toolbox for Mac to write iPhone unit tests and that works just fine, but it's nice to find out that it's now built in to the SDK.

No comments: