Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios OCMockito:验证是否在将来某个时候调用了mock的方法_Ios_Unit Testing_Ocmockito - Fatal编程技术网

Ios OCMockito:验证是否在将来某个时候调用了mock的方法

Ios OCMockito:验证是否在将来某个时候调用了mock的方法,ios,unit-testing,ocmockito,Ios,Unit Testing,Ocmockito,首先我模仿一个物体。 然后我会做一些事情,让对象的特定方法被调用。调用是异步的 所以我想验证的是:在最多5秒钟内,应该调用mock对象的这个方法 有什么想法吗?OCMockito还不支持异步验证。在此之前,我建议使用一个手摇的mock,以及OCHamcrest的assertWithTimeout 例如,这里有一个手动翻滚的模拟来确认调用了fooBar: @interface MockFoo : NSObject @property (nonatomic, assign) BOOL fooBarW

首先我模仿一个物体。 然后我会做一些事情,让对象的特定方法被调用。调用是异步的

所以我想验证的是:在最多5秒钟内,应该调用mock对象的这个方法


有什么想法吗?

OCMockito还不支持异步验证。在此之前,我建议使用一个手摇的mock,以及OCHamcrest的
assertWithTimeout

例如,这里有一个手动翻滚的模拟来确认调用了
fooBar

@interface MockFoo : NSObject
@property (nonatomic, assign) BOOL fooBarWasCalled;
- (void)fooBar;
@end

@implementation MockFoo

- (void)fooBar
{
    self.fooBarWasCalled = YES;
}

@end
然后是奥恰姆克雷斯特:

assertWithTimeout(5, thatEventually(@(myMock.fooBarWasCalled), isTrue());

谢谢Jon,我已经考虑过了,但是我没有找到一种方法来将mockito的verify()转换成可以断言的bool值,我遗漏了什么?我添加了一个简单的示例。