2009-10-31 7 views
2

나는있는 NSURLConnection의 동작을 테스트하려고 OCMock를 사용하고 여기에 불완전 시험은 다음과 같습니다."[NSProxy doesNotRecognizeSelector"...] "

#include "GTMSenTestCase.h" 
#import <OCMock/OCMock.h> 

@interface HttpTest : GTMTestCase 

- (void)testShouldConnect; 

@end 

@implementation HttpTest 

- (void)testShouldConnect { 
    id mock = [OCMockObject mockForClass:[NSURLConnection class]]; 

    NSURL *url = [NSURL URLWithString:@"http://www.google.com"]; 
    NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:mock startImmediately:NO]; 

    [[mock expect] connection:connection didReceiveResponse:OCMOCK_ANY]; 
} 

@end 

클래스와 조롱 분류 방법, 어떤 대리인 방법 연결 : didReceiveresponse : 내가 오류를 얻을 수 있습니다 :?

Unknown.m:0:0 Unknown.m:0: error: -[HttpTest testShouldConnect] : *** -[NSProxy doesNotRecognizeSelector:connection:didReceiveResponse:] called! 

사람이 문제가 있었다

답변

4

NSURLConnection의 모의 객체를 생성 한 것처럼 보입니다. 그러나 NSProxy 경고가 올바른지, NSURLConnection 개체에 선택기 연결이 없습니다. didReceiveResponse : - 프로토콜을 구현하는 개체로 전달되는 선택기입니다.

NSURLConnectionDelegate를 구현하는 객체를 조롱해야합니다. didReceiveResponse : 대리자 프로토콜 연결을 지정으로 오류 : 나는 OCMock을 사용한 경험이 많지 않은

을하지해야하지만 이것은 컴파일 오류 제거하는 것 같다

@interface ConnectionDelegate : NSObject { } 
- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response; 
@end 

@implementation ConnectionDelegate 
- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { } 
@end 



@interface ConnectionTestCase : SenTestCase { } 
@end 

@implementation ConnectionTestCase 

- (void)testShouldConnect { 
id mock = [OCMockObject mockForClass:[ConnectionDelegate class]]; 

NSURL *url = [NSURL URLWithString:@"http://www.google.com"]; 
NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:mock startImmediately:NO]; 

[[mock expect] connection:connection didReceiveResponse:OCMOCK_ANY]; 
} 

@end 

희망이,

도움을 프로젝트 라이브러리가 YES에 GCC 옵션 COPY_PHASE_STRIP 세트로 컴파일되는 때

0

그래서 기호가 표시되지 않은이 오류에 달렸다. 그런 다음 해당 라이브러리에 대해 테스트가 실행되어 스텁으로 설정해야하는 메소드를 볼 수 없었습니다. COPY_PHASE_STRIP=NO은 문제를 해결했습니다.