【发布时间】:2014-12-22 13:13:25
【问题描述】:
我浏览了各种类模拟示例,如下所示:
https://groups.google.com/forum/#!topic/kiwi-bdd/hrR2Om3Hv3I
https://gist.github.com/sgleadow/4029858
Mocking expectations in Kiwi (iOS) for a delegate
类Test有一个类方法fetch。
我想要实现的是查看一个类的方法是否在我要测试的类的工作期间被调用。
我做什么:
it(@"test", ^{
id mock = [KWMock mockForClass:[Test class]];
[[mock should] receive:@selector(fetch)];
Repository *rep = [[Repository sharedInstance] rep]; //method `rep` invokes [Test fetch] at some point
});
测试失败并出现以下错误:
[FAILED], expected subject to receive -fetch exactly 1 time, but received it 0 times
我做错了什么? spy 机制应该如何作用于类方法?
【问题讨论】:
标签: ios unit-testing kiwi