我正在使用OCMock 3进行单元测试。我有一个名为processInfo
的非常简单的函数来测试:
@implementation MyService
// in my test case, I want to test this function
-(void) processInfo{
...
[self handleDataWith:infoData name:someName];
}
-(void) handleDataWith:(NSData*)data name:(NSString*)name{
...
}
我的测试用例应该是这样的,以捕获参数(受this answer启发):
-(void) testProcessInfo {
id serviceMock = [OCMockObject mockForClass:[MyService class]];
// Wow!Wow! wait, the answer I linked above only talk about how to capture a single argument,
//BUT I have two arguments to capture, how to do then?
OCMExpect([serviceMock handleDataWith:[OCMArg checkWithBlock:^(id value){
// Capture argument here...but what about several arguments?
}]]);
我上面链接的答案讲述了如何使用[OCMArg checkWithBlock:^(id value)]
捕获单个参数,但我想捕获两个参数。怎么办呢?
总的来说,我很难在互联网上找到有关如何捕获多个参数的单元测试 OCMock v3 的文档。谁知道怎么做?
答案 0 :(得分:0)
正如我在对您的其他问题(Check argument value passed into function in unit test)的回答中提到的那样,您必须使用andDo
。