방금 작업중인 라이브러리 테스트에 사용할 OCMock을 다운로드했습니다. 내가 시도한 첫 번째 스텁에서 문제가 발생했습니다. 나는 모든 네트워크 작업을 처리하는 객체를 가지고 있으며,받은 객체의지도를 그리는 객체가있다. 지도 객체를 테스트하기 위해 네트워크 객체를 모의하고 싶습니다. 당신이 볼 수 있듯이 오류가 시험 자체에서 오지 않도록, 내가 3 개 속성을 유지OCMock throwing EXC_BAD_ACCESS
@interface STMap()
@property (retain) STNetwork* router;
@end
@interface testSTMap : XCTestCase <STMapDelegate>
@property (retain) MKMapView* mapView;
@property (retain) STMap* testMap;
@property (retain) id mockRouter;
@end
@implementation testSTMap
- (void)setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
self.mapView = [[MKMapView alloc] init];
self.testMap = [[STMap alloc] initWithDelegate:self andKey:@"test" andRouteOptions:nil
andMap:self.mapView andOverlayLevel:MKOverlayLevelAboveLabels];
self.mockRouter = OCMClassMock([STNetwork class]);
self.testMap.router = self.mockRouter;
}
- (void)testExample {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
OCMStub([self.mockRouter getRouteForStartLat:[OCMArg any] andStartLon:[OCMArg any]
andEndLat:[OCMArg any] andEndLon:[OCMArg any]])._andReturn(nil);
[self.testMap addRouteForStartLat:@0 andStartLon:@0 andEndLat:@1 andEndLon:@1];
}
:
여기 내 테스트 파일입니다. 내지도 개체는 네트워크 개체를 포함하여 개인 속성을 가지고 있기 때문에 이것이 시험에서 mock 개체로 변경할 수있는 확장을 만든 이유입니다. 이 시점에서 아직지도 객체를 호출하지 않기 때문에 코드를 게시하지 않겠습니다.
@interface STNetwork()
@property (retain) NSString* url;
@property (weak) id<STNetworkDelegate> delegate;
@property (retain) NSString* key;
@property (copy) CompletionBlock completionHandler;
@end
내가 위임 속성이 사이클을 유지 피하기 위해 약한해야합니다 알고, 그래서 나는이 오류를 일으키는 의심 :
네트워크 객체 (모든 속성 비공개)과 같습니다.
오류는 OCMStub
과 함께 줄에 표시됩니다. 추적 :
OCMStubRecorder.m
- 라인 112 : (OCMIsObjectType ([objCType을 aValue])) 경우. 이 시점에서aValue
은 nil입니다. 문제가 시작되는 곳입니다. 그러나aValue
이 어디서 왔는지는 알 수 없습니다.OCMFunctions.m
라인 78 : const char * unqualifiedObjCType = OCMTypeWithoutQualifiers (objCType);. 여기서objCType
은 NULL이므로aValue
이 nil이므로 예상대로입니다.OCMFunctions.m
라인 40 : (strchr ("rnNoORV", objCType [0])! = NULL)입니다. 나쁜 액세스가 실제로 발생하는 곳입니다.
것들 내가 시도 :
- 가 변경 [OCMArg 어떤] 하드 코딩 값
- 있어 이들의 모의
없음의 숫자, NSNull 반환하고, 무효로 나쁜 접근을 지나쳐. 어떤 도움이라도 대단히 감사합니다!
- (void)getRouteForStartLat: (NSNumber*) startLat
andStartLon: (NSNumber*) startLon
andEndLat: (NSNumber*) endLat
andEndLon: (NSNumber*) endLon;
'getRouteForStartLat : andStartLon : andEndLat : andEndLon :'메서드의 선언을 제공 할 수 있습니까? –
@ErikDoernenburg 귀하가 요청한 선언문을 추가했습니다. – gamda