我試圖寫一個XCTest(iOS7,XCode5)與OCMock一起CLLocationManager模擬類方法。無法使用OCMock與iOS7
我有它實現了CLLocationManagerDelegate協議的類,並且有一個屬性是一個CLLocationManager的一個實例。 (我將CLLocationManager的實例提供給我的initialiser方法,以便我可以在運行時或測試中注入它)。
當測試委託類,我創建了一個模擬CLLocationManager。
在測試中,我要實現的是這樣的:
[[[[mockLocationManager stub] classMethod] andReturnValue:kCLAuthorizationStatusDenied] authorizationStatus];
result = [delegateUnderTest doMethod];
//Do asserts on result etc etc
的問題是,Xcode是抱怨我的代碼。
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是int我明白(如在一個typedef定義)。 所以,我不能用
[[[[mockLocationManager stub] classMethod] andReturn:kCLAuthorizationStatusDenied] authorizationStatus];
其期望的對象(「andReturn」是一個「身份證」)。
任何想法?
謝謝。完成這個訣竅。我曾嘗試過@kCLAuthorizationStatusDenied(沒有括號),這似乎是正確的。那些額外的括號@(kCLAuthorizationStatusDenied)將我排序。 –