我在SenTestCase类中有以下Objective C测试代码。我没有得到任何错误,但httpReceiveDataFinished方法永远不会被调用。这是因为在委托有机会处理http方法之前测试结束了吗?如何使测试方法等待代理完成处理?
如果是这种情况,我该如何分离线程(或类似的东西)以使测试等待几秒钟?
非常感谢任何帮助。我已经编写了Java多年,但Objective-C只有几天。
- (void)testExample
{
HttpClient *client = [[HttpClient alloc] init];
client.method = METHOD_GET;
client.followRedirects = YES;
[client processRequest:@"http://google.com" delegate:self];
NSLog(@"Test Over");
}
-(void) httpReceiveError:(NSError*)error {
NSLog(@"***\n%@\n***",[error description]);
}
- (void) httpReceiveDataChunk:(NSData *)data {
[self.httpResponseData appendData:data];
}
-(void) httpReceiveDataFinished {
NSString *result = [[NSString alloc]
initWithData:self.httpResponseData
encoding:NSUTF8StringEncoding];
NSLog(@"***\nRESULT: %@ \n***",result);
}
http://stackoverflow.com/questions/1077737/ocunit-test-for-protocols-callbacks-delegate-in-objective-c –
真棒。像魅力一样工作。 –