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 –
굉장합니다. 매력처럼 일했다. –