我正在尝试测试一个实现两个类方法的类NSURLConnection
,但不断收到错误:
error: testSyncConnection (MyURLConnectionTest) failed: *** -[NSProxy doesNotRecognizeSelector:sendSynchronousRequest:returningResponse:error:] called!
这是接口MyURLConnection
:
@interface MyURLConnection : NSURLConnection
+ (void) sendAsynchronousRequest:(NSURLRequest *)request queue:(NSOperationQueue*) queue completionHandler:(void (^)(NSURLResponse*, NSData*, NSError*)) handler;
+ (NSData *) sendSynchronousRequest:(NSURLRequest *)request returningResponse (NSURLResponse **)response error:(NSError **)error;
@end
这是我试图模拟它的方式:
- (void)testSyncConnection
{
id testConnection = [OCMockObject mockForClass:[MyURLConnection class]];
[[[testConnection stub] andReturn:Nil] sendSynchronousRequest:Nil
returningResponse:Nil
error:Nil];
//rest of test...
}
在存根部分失败,产生我在上面发布的错误..
我还确保将MyDURLConnection
实现也添加到测试目标中。
我在这里缺少什么提示?