views:

10

answers:

0

I am trying to write unit tests for a class that manages a UIImagePickerController. Yet, I still would like to link against UIKit to pull in other symbols I don't care about stubbing.

Usually, I use OCMock for mocking out instance methods. With UIImagePickerController I'm interested in mocking out class methods which OCMock can't do. I'm aware of method swizzling, but I'm interested in creating a full-class stub.

I have experience with MSDev and VC++. There, you could mock out an object file by providing an implementation in the project. The linker would prefer symbols defined in local object files before looking into linked libraries.

So, in XCode I created a UIImageViewController+Stub.m category and implemented all the symbols in this file that the compiler complained about.

Alas, when I build the UT target I get this:

objc[67927]: Class UIImagePickerController is implemented in both /../build/Debug-iphonesimulator/Test Runner.app/Test Runner and /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.1.sdk/System/Library/Frameworks/UIKit.framework/UIKit. One of the two will be used. Which one is undefined.

This looks like it's a coin toss as to which class XCode will use. Is there a way to force XCode to use my stub?

The alternatives to this approach is to not link against UIKit and supply stubs for every symbol referenced in UIKit. Of course, I'd look more seriously at method swizzling before considering this approach as the idea of writing a full UIKit stub is a bit daunting.