gpt4 book ai didi

ios - 如何监视 Kiwi 中的类方法?

转载 作者:行者123 更新时间:2023-11-29 02:25:27 25 4
gpt4 key购买 nike

我浏览了各种类模拟示例,如下所示:

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 机制如何在类方法上工作?

最佳答案

[[Test should] receive:@selector(fetch)];

这就是你应该如何检查它,因为它是一个方法类而不是一个实例类,你不需要模拟类对象。编写时的自动完成可能不会显示它,因此您必须强制执行此操作。

关于ios - 如何监视 Kiwi 中的类方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27603447/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com