我怎样才能让 OCMock 让我在 UIKit 类上存根一个类别方法?
我试图在我的应用程序的测试中模拟 UITabBarController 。 我在另一个文件的其他地方定义了该类的类别方法,该方法与我的测试类中的 ocmock 一起导入。 我想要做的是这样的:
- (void) setUp
{
id mockTabController = [OCMockObject mockForClass:[UITabBarController class]];
[[[mockTabController stub] andReturn:nil] displayedViewController];
// displayedViewController is the category method
}
但是当我这样做并且测试到达该存根调用时,我收到一条错误消息:
[NSProxy doesNotRecognizeSelector:displayedViewController] called!
我需要做一些特定的事情来允许 ocmock 识别内置框架类上的类别方法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我解决了这个问题; 其中定义的类类别的文件不在我的项目中的正确目标中。 它在主要目标中,但不在单元测试目标中。 将其添加到正确的位置使其工作顺利。
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.