짧은 버전 :비웃음 예상 질문의
은 다음과 키위/아이폰 OS 모의 기대에 문제가 있나요? 질문의
[[mockDelegate should] receive:@selector(connectionDidSucceedWithText:andStatus:) withArguments:[testString1 stringByAppendingString:testString2],theValue(value),nil];
긴 버전 :
은 내가 NSConnection을 처리하는 간단한 클래스 키위, 아이폰 OS에서 테스트를 작성하려합니다. 클래스가 NSConnection에서 콜백을 처리하는지 테스트하려면 NSConnection 메서드가 정상적으로 수행하는 대리자 메서드를 전달합니다. 내 클래스를 사용하는 사람에게 데이터를 다시 보내는 클래스의 대리자가 있습니다. 클래스를 테스트하려면 조롱 한 델리게이트를 삽입 한 다음 원하는 메서드가 호출되는지 확인해야합니다. 간단한 키위 시험이 :)
내 코드는 다음과 같이
//Some ivars declared elsewhere:
testString1 = @"asd323/4 d14";
testString2 = @"as98 /2y9h3fdd14";
testData1 = [testString1 dataUsingEncoding:NSUTF8StringEncoding];
testData2 = [testString2 dataUsingEncoding:NSUTF8StringEncoding];
mockURLRespons = [NSHTTPURLResponse mock];
int value = 11111;
id mockDelegate = [KWMock mockForProtocol:@protocol(SharepointConnectionDelegate)];
communicator = [[SharepointCommunicator alloc] init];
it (@"should send recieve data back to delegate2", ^{
[communicator setDelegate:mockDelegate];
[mockURLRespons stub:@selector(statusCode) andReturn:theValue(value)];
[(id)communicator connection:niceMockConnector didReceiveResponse:mockURLRespons];
[(id)communicator connection:niceMockConnector didReceiveData:testData1];
[(id)communicator connection:niceMockConnector didReceiveData:testData2];
[(id)communicator connectionDidFinishLoading:niceMockConnector];
[[mockDelegate should] receive:@selector(connectionDidSucceedWithText:andStatus:) withArguments:[testString1 stringByAppendingString:testString2],theValue(value),nil];
});
그리고 내 SharepointCommunicator.m에서
:-(void)connection:(NSURLConnection *)aConnection didReceiveResponse:(NSURLResponse *)response {
if (connection != aConnection) {
[connection cancel];
connection = aConnection;
}
responseData = [[NSMutableData alloc] init];
statusCode = [(NSHTTPURLResponse*)response statusCode];
}
-(void)connection:(NSURLConnection *)aConnection didReceiveData:(NSData *)data {
if (aConnection != self.connection)
return;
[responseData appendData:data];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *txt = [[NSString alloc] initWithData:responseData encoding: NSASCIIStringEncoding];
NSLog(@"Statuscode: %i", statusCode);
NSLog(@"Data is: %@",txt);
[delegate connectionDidSucceedWithText:txt andStatus:statusCode];
[self.connection cancel];
self.connection = nil;
}
이 코드는 작동하고 정확합니다. 검사 점을 사용하여 디버깅하면 예상대로 수행됩니다. statusCode의 값은 11111이고 txt는 testString1 + textString2입니다. 그럼에도 불구하고 다음과 같은 오류 테스트에서의 마지막 행에 실패
error: -[kiwiSharepointCommunicatorTest Sharepointcommunicator_AStateTheComponentIsIn_ShouldSendRecieveDataBackToDelegate2] : 'Sharepointcommunicator, a state the component is in, should send recieve data back to delegate2' [FAILED], mock received unexpected message -connectionDidSucceedWithText:"asd323/4 d14as98 /2y9h3fdd14" andStatus:11111
Test Case '-[kiwiSharepointCommunicatorTest Sharepointcommunicator_AStateTheComponentIsIn_ShouldSendRecieveDataBackToDelegate2]' failed (3.684 seconds).
여전히 같은 오류를 발생 시험에서 마지막 행을 제거. withArguments : I 수신에 대한 이해를 추측 잘못 ..
키위의 주장과 관련이 있다고 가정합니다. 아마도 객체에 대한 포인터와 일치하는 것입니까? 그런 이유로 동일한 문자열이 포함되어 있어도 문자열이 일치하지 않는 이유는 무엇입니까? 또는 아마도 int 같은 non-object의 일치를 처리 할 수 없습니다 ... – Sunkas
비슷한 문제가 있습니다. 대리자가 위임자 (모의)에게 문자열을 전달하고 있습니다. – quantumpotato