我浏览了各种类模拟示例,如下所示:
https://groups.google.com/forum/#!topic/kiwi-bdd/hrR2Om3Hv3I
https://gist.github.com/sgleadow/4029858
该类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
我究竟做错了什么?间谍机制应该如何作用于类方法?