如何使用OCMock for iOS模拟私有属性? [英] How do you mock out private properties with OCMock for iOS?

查看:442
本文介绍了如何使用OCMock for iOS模拟私有属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个私有属性,在我的类的.m文件中声明了要测试,让我们称之为ClassUnderTest。 ClassUnderTest实例化一个ClassToBeMocked的实例。如何使用OCMock模拟ClassToBeMocked的实例并将其分配给ClassUnderTest?

I have a private property that is declared in the .m file of my class to be tested, let's call it ClassUnderTest. ClassUnderTest instantiates an instance of ClassToBeMocked. How do I use OCMock to mock out an instance of the ClassToBeMocked and assign it to the ClassUnderTest?

推荐答案

重新声明属性在你的测试类。你可以对私有方法做同样的事情。在ClassUnderTestTest.m中:

Re-declare the property in your test class. You can do the same for private methods. In ClassUnderTestTest.m:

@interface ClassUnderTest ()

@property(retain)ClassToBeMocked *instanceToBeMocked;

-(void)somePrivateMethod;

@end

这篇关于如何使用OCMock for iOS模拟私有属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆