objective-c – 如何检查客观C单元测试中的私人成员?
发布时间:2020-12-14 17:40:59 所属栏目:百科 来源:网络整理
导读:考虑这个课程: @interface SampleClass : NSObject { NSMutableArray *_childs;}- (void)addChild:(ChildClass *)child;- (void)removeChild:(ChildClass *)child;@end 如果_childs数组包含一个对象而没有添加属性来访问它,我如何测试添加子项时(因为我不希
考虑这个课程:
@interface SampleClass : NSObject { NSMutableArray *_childs; } - (void)addChild:(ChildClass *)child; - (void)removeChild:(ChildClass *)child; @end 如果_childs数组包含一个对象而没有添加属性来访问它,我如何测试添加子项时(因为我不希望允许客户端代码访问_childs数组)? 解决方法
在类扩展中为它创建一个@property,并使用该属性进行所有访问,这样您就可以测试并使用相同的代码.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |