How can i get OCMock to let me stub a category method on a UIKit class?
Asked Answered
M

1

6

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?

Mettle answered 13/7, 2009 at 22:56 Comment(0)
M
16

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.

Mettle answered 21/7, 2009 at 5:25 Comment(1)
Thanks for documenting your own solution. It helped me :)Deoxyribose

© 2022 - 2024 — McMap. All rights reserved.