【发布时间】:2015-01-30 07:45:53
【问题描述】:
我正在使用Firebase iOS SDK,我正在努力弄清楚如何使用 Kiwi 全面测试一些 Firebase 方法调用。
我正在使用 Firebase 实例来“监视”路径:
Firebase *streamsReference = [self.firebaseRef childByAppendingPath:@"streams"];
然后使用 streamsReference 观察事件:
[streamsReference observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) {
// do stuff in the block here
}];
我想测试一下代码块中的效果。
这是我目前得到的:
it(@"should handle incoming connections as a hook for WebRTC", ^{
id mockFirebaseClass = [KWMock mockForClass:[Firebase class]];
// mock Firebase object to handle "/streams" path
id mockFirebaseStreamsReference = [KWMock mockForClass:[Firebase class]];
// return the streams reference object via the mock Firebase object
[mockFirebaseClass stub:@selector(childByAppendingPath:) andReturn:mockFirebaseStreamsReference];
// attempt to capture the block in the second param
KWCaptureSpy *spy = [mockFirebaseStreamsReference captureArgument:@selector(observeEventType:withBlock:) atIndex:1];
// inject the Firebase mock into the test class
classUnderTest.firebaseRef = mockFirebaseClass;
// capture the block from the spy
void(^blockToRun)() = spy.argument;
// call method that will invoke the Firebase observeEventType:withBlock method
[classUnderTest setupIncomingRemoteConnectionHandler];
// run the captured block
blockToRun(nil);
...
... expectations go here
...
});
当我运行测试时,它因Argument requested has yet to be captured 错误而失败 - 这表明我以错误的顺序进行操作。任何人都可以在这里看到我哪里出错了吗?
【问题讨论】:
标签: ios unit-testing mocking tdd kiwi