この(loginWithEmail法がよく、期待として期待されます)動作コード、検討:このコード対OCMock、プロトコル上でメソッドを期待できないのはなぜですか?
_authenticationService = [[OCMockObject mockForClass:[AuthenticationService class]] retain];
[[_authenticationService expect] loginWithEmail:[OCMArg any] andPassword:[OCMArg any]];
:
_authenticationService = [[OCMockObject mockForProtocol:@protocol(AuthenticationServiceProtocol)] retain];
[[_authenticationService expect] loginWithEmail:[OCMArg any] andPassword:[OCMArg any]];
2番目のコード例は、次の行2に失敗エラー:
:*** -[NSProxy doesNotRecognizeSelector:loginWithEmail:andPassword:] called! Unknown.m:0: error: -[MigratorTest methodRedacted] : ***
-[NSProxy doesNotRecognizeSelector:loginWithEmail:andPassword:] called!
AuthenticationServiceProtocolは、メソッドを宣言します
@protocol AuthenticationServiceProtocol <NSObject>
@property (nonatomic, retain) id<AuthenticationDelegate> authenticationDelegate;
- (void)loginWithEmail:(NSString *)email andPassword:(NSString *)password;
- (void)logout;
- (void)refreshToken;
@end
そして、それはクラスで実装されています
@interface AuthenticationService : NSObject <AuthenticationServiceProtocol>
これは、iOS用OCMockを使用しています。
モックがmockForProtocol
のときにexpect
が失敗するのはなぜですか?
ソースからOCMockを構築していますか? 'OCProtocolMockObject'の' methodSignatureForSelector: 'メソッドにブレークポイントを入れることは興味深いでしょう。 –
ソースからビルドしていない、ちょうど静的ライブラリをダウンロードしました。 – driis
実際のプロトコル宣言を投稿できますか? –