2013-09-28 5 views
3

OCMock과 함께 XCTest (iOS7, XCode5)를 작성하려고합니다.OCMock with iOS7을 사용하여 CLLocationManager에서 클래스 메서드를 모의 할 수 없습니다.

CLLocationManagerDelegate 프로토콜을 구현하는 클래스가 있고 CLLocationManager의 인스턴스 인 속성이 있습니다. (필자는 CLLocationManager의 인스턴스를 내 initialiser 메서드에 제공하여 런타임에 테스트하거나 테스트 할 수 있도록합니다.)

위임 클래스를 테스트 할 때 모의 CLLocationManager를 만듭니다.

[[[[mockLocationManager stub] classMethod] andReturnValue:kCLAuthorizationStatusDenied] authorizationStatus]; 
result = [delegateUnderTest doMethod]; 
//Do asserts on result etc etc 

문제는, 엑스 코드 내 코드에 대해 불평 : 테스트에서

, 나는 이런 식으로 뭔가를 달성하고 싶다.

test.m:79:68: Implicit conversion of 'int' to 'NSValue *' is disallowed with ARC 
test.m:79:68: Incompatible integer to pointer conversion sending 'int' to parameter of type 'NSValue *' 

kCLAuthorizationStatusDenied는 (TypeDef에 정의 된대로) 이해할 수있는 정수입니다. 그래서, 객체를 기대

[[[[mockLocationManager stub] classMethod] andReturn:kCLAuthorizationStatusDenied] authorizationStatus]; 

을 사용할 수 없습니다 ('andReturn'는 'ID'이다).

아이디어가 있으십니까?

답변

2

NSValue 인스턴스의 값을 입력하고 프리미티브 값 자체를 전달하지 않아야합니다. 예를 들면 :는

[[[mockLocationManager stub] andReturnValue:@(kCLAuthorizationStatusDenied)] authorizationStatus]; 

상기 NSNumber S 용 대물-C 리터럴 구문을 이용한다. 또한, 위의 classMethod 호출을 생략했습니다. CLLocationManager에는 인스턴스 메소드 authorizationStatus이 없습니다. 이것에 대한

더 많은 지원하여 OCMock website에서 찾을 수 있습니다 : 값 인수와 함께 사용해야합니다 :이 방법은 다음 andReturnValue 기본 유형을 반환

합니다. 프리미티브 유형을 직접 전달할 수는 없습니다. 당신이 NSValue 예를 대신 int 전달됩니다 - 또한 컴파일러 오류가 당신을 말하고 무엇

.

+0

감사합니다. 속임수를 쓰자. @kCLAuthorizationStatusDenied (괄호없이)를 시도했는데, 옳은 것으로 보였다. 그 여분 괄호 @ (kCLAuthorizationStatusDenied)는 나를 분류했다. –