views:

97

answers:

2

I'm trying to mock a UITabBarController in my app's tests. I have a category method on that class defined elsewhere in another file that gets imported along with ocmock in my test class. what i'm trying to so is this:

- (void) setUp
{
    id mockTabController = [OCMockObject mockForClass:[UITabBarController class]];
    [[[mockTabController stub] andReturn:nil] displayedViewController]; 
    // displayedViewController is the category method
}

but when i do and the test gets to that stub call, i get an error saying:

[NSProxy doesNotRecognizeSelector:displayedViewController] called!

Is there something specific i need to do to allow ocmock to recognize category methods on built in framework classes?

+1  A: 

I figured out the problem; the file that had the class category defined in it wasn't in the correct target in my project. It was in the main target but not the unit test target. adding it to the right place made it work swimmingly.

Kevlar
A: 

This was incredibly helpful. Thanks.