请参阅#if 0 ...#endif,如果启用,则模拟按预期工作,在调用方法preferencesGeneralUnits时返回1;如果禁用,则模拟仍返回先前的值0,尽管我们要求他返回1。
我的问题是OCMock错误吗?还是OCMock的预期用途?谢谢。
对于2.0.1和从最新的源代码构建都不利。
任何想法或讨论将不胜感激,在此先感谢。
- (void) testFormattedDistanceValueWithMeters{
id mockSettings = [OCMockObject mockForClass:[TnSettings class]];
id mockClientModel = [TnClientModel createMockClientModel];
[[[mockClientModel stub] andReturn:mockSettings] settings];
[[[mockSettings stub] andReturn:[NSNumber numberWithInt:0]] preferencesGeneralUnits];
NSNumber *meters = [NSNumber numberWithDouble:0.9];
distance = [NSString formattedDistanceValueWithMeters:meters];
STAssertEqualObjects(distance, @"0.9", @"testformattedEndTimeForTimeInSeconds failed");
//--------------See here---------------------
#if 0
mockSettings = [OCMockObject mockForClass:[TnSettings class]];
mockClientModel = [TnClientModel createMockClientModel];
[[[mockClientModel stub] andReturn:mockSettings] settings];
#endif
[[[mockSettings stub] andReturn:[NSNumber numberWithInt:1]] preferencesGeneralUnits];
meters = [NSNumber numberWithDouble:1];
distance = [NSString formattedDistanceValueWithMeters:meters];
STAssertEqualObjects(distance, @"3.3", @"testformattedEndTimeForTimeInSeconds failed");
[TnClientModel releaseInstance];
}
最佳答案
Erik Doernenburg的解释是合理的。