这是一个 OCUnit 测试,它简单地对 的方法playerID
进行存根GKTurnBasedParticipant
:
#import <GameKit/GameKit.h>
#import "OnlineMatchTest.h"
#import "OCMock.h"
@implementation OnlineMatchTest
- (void)setUp {
GKTurnBasedParticipant *participant = [OCMockObject mockForClass:[GKTurnBasedParticipant class]];
[[[(id)participant stub] andReturn:@"123"] playerID];
}
- (void)test {
// Do nothing.
}
@end
但是,测试失败,就好像该方法-[GKTurnBasedParticipant playerID]
不存在一样:
Test Case '-[OnlineMatchTest test]' started.
Unknown.m:0: error: -[OnlineMatchTest test] : *** -[NSProxy doesNotRecognizeSelector:playerID] called!
Test Case '-[OnlineMatchTest test]' failed (0.000 seconds).
为什么会这样?我正在针对 iOS 6.1 SDK 进行编译,所以这种方法肯定存在。