【问题标题】:How to spy on a class method in Kiwi?如何监视 Kiwi 中的类方法?
【发布时间】: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


    【解决方案1】:
    [[Test should] receive:@selector(fetch)];
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-08
      • 2013-10-24
      • 2017-06-16
      • 1970-01-01
      • 2021-07-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多