在使用OCMockito时,下面的功能非常好:
DSAPIManager *mockAPIManager = mock([DSAPIManager class]);
[given([mockAPIManager initWithBaseURL:[mockAPIManager baseURL]]) willReturn:[DSAPIManager sharedAPIManager]];但是,当我在一个包含多个参数的方法上尝试相同的操作时(请参阅下面的代码),我会得到一个“参数类型‘'void’是不完整的‘编译器错误。
DSAPIManager *mockAPIManager = mock([DSAPIManager class]);
[given([mockAPIManager setLoginCredentialsWithEmail:@""
password:@""]) willReturn:@""];有人知道该怎么做吗?
编辑
我提出这个问题的初衷是解决当我尝试以下操作时得到编译器错误的问题:
[given([mockAPIManager setLoginCredentialsWithEmail:@"" password:@""]) willDo:^id(NSInvocation *invocation) {
// Mock implementation goes here
}];我试图模仿的方法的方法签名是:
- (void)setLoginCredentialsWithEmail:(NSString *)email password:(NSString *)password;我实际上要做的是模拟void方法的实现。(给定一个void方法,用块模拟该方法的实现。就我的目的而言,该方法返回一个包含两个参数的完成块。我想构造这两个参数,然后在模拟的实现块中运行完成块。)
发布于 2015-03-16 04:59:06
OCMockito还不支持无效方法的顽固。这是因为在willThrow:和willDo:出现之前,没有必要。它很快就会被添加为一个功能。您可以跟踪https://github.com/jonreid/OCMockito/pull/93的进度。
发布于 2016-11-11 15:28:03
现在您可以像这样使用givenVoid了
[givenVoid([mockAPIManager setLoginCredentialsWithEmail:@"" password:@""]) willDo:^id(NSInvocation *invocation) {
// Mock implementation goes here
}];https://stackoverflow.com/questions/29043188
复制相似问题