1

参见#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];
    }
4

1 回答 1

1

Erik Doernenburg 的解释是合理的。

于 2012-07-13T01:43:50.520 回答