通过以下单元测试,我使用 Mockito 来模拟 NSUserDefaults 但是当我尝试使用 OCHamcrest 匹配器来测试参数是否是 NSDictionary 的实例时,我收到警告:
将“id{HCMatcher}”发送到不兼容类型“NSDictionary *”的参数
NSUserDefaults *userDefaultsMock = mockClass([NSUserDefaults class]);
//OR -- NSUserDefaults *userDefaultsMock = mock([[NSUserDefaults standardUserDefaults]class]);
Engineer *sut = [[Engineer alloc]init];
[given([userDefaultsMock stringForKey:@"engineerId"]) willReturn:@"02345"];
BOOL result = [sut setCurrentEngineerId:@"02345" userDefaults:userDefaultsMock];
[verify(userDefaultsMock) registerDefaults:instanceOf([NSDictionary class])];
谢谢