单元测试失败 - 为什么?

时间:2010-07-16 15:15:23

标签: iphone unit-testing xcode

我的单元测试套件中有以下测试:

STAssertEquals(0, [[newUnit itemsWithinBasketFrom:[NSDate dateYesterday] through:[NSDate dateTomorrow]] count],
               @"A unit with no items should return 0 when asked for items in place within a date range. (count=%i)",
               [[newUnit itemsWithinBasketFrom:[NSDate dateYesterday] through:[NSDate dateTomorrow]] count]);

构建控制台的输出是:Type mismatch -- A unit with no items should return nil when asked for items in basket within a date range. (count=0)

如果count为0,并且我正在测试它与0的相等性,那么为什么我会出现类型不匹配?

谢谢!

2 个答案:

答案 0 :(得分:3)

count返回NSUIntegerunsigned int。您将期望值设置为0,即int。那些类型是不同的。将您的0转换为NSUInteger,例如(NSUInteger)0或使用0U

答案 1 :(得分:0)

IMO,问题不在于计数是否为0。返回的[[newUnit itemsInPlaceWithinDateRangeFrom:[NSDate dateYesterday] through:[NSDate dateTomorrow]] count]类型是什么。也许你的类型不正确(如double),然后当你尝试打印它时,它似乎是0.而且因为它无法比较int和double,它会产生类型不匹配。这只是我的猜测

相关问题