繁体   English   中英

单元测试失败-为什么?

[英]Unit Test Fails — Why?

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

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) 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测试其相等性,那么为什么会出现类型不匹配的情况?

谢谢!

count返回NSUInteger ,它是unsigned int 您将期望值设置为0,即int 这些类型是不同的类型。 将您的0像(NSUInteger)0一样强制转换为NSUInteger或使用0U

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM