Wednesday, October 6, 2010

iOS SDK 4.1 Breaks Unit Tests

I ran into this problem a couple of weeks ago, but didn't get around to blogging about it until today. If you use the OCUnit test framework that's part of Xcode to write unit tests, upgrading to iOS SDK 4.1 will give you a rude surprise:

Run unit tests for architecture 'i386' (GC OFF) did not finish

An internal error occurred when handling command output: -[XCBuildLogCommandInvocationSection testName]: unrecognized selector sent to instance 0x2010cff80

An internal error occurred when handling command output: -[XCBuildLogCommandInvocationSection setTestsPassedString:]: unrecognized selector sent to instance 0x2010cff80

An internal error occurred when handling command output: -[XCBuildLogCommandInvocationSectionRecorder endMarker]: unrecognized selector sent to instance 0x2009b8580

It seems there's a mismatch between Xcode and OCUnit in the 4.1 SDK release. At first I wasn't able to find a workaround. I was going to install iOS 4.2 SDK beta 1 anyway, so I went ahead and did that and found that the problem had been fixed. The beta SDK has been working fine for me (though you should still use the 4.1 release SDK if you're building for submission to the app store).

Checking back on this problem, there are now a couple of workarounds. Apple posted some Objective-C code in their developer forums that monkey patches the problem. And Andy W posted a simple workaround on Stack Overflow.

This isn't the first time that Apple has broken their officially supported unit testing framework with an update to Xcode. It's kinda ironic, but I guess they don't have good test coverage of their test framework.

No comments: