开发者

Unit Test Fails -- Why?

开发者 https://www.devze.com 2023-01-07 20:41 出处:网络
I have the following test in my unit test suite: STAssertEquals(0, [[newUnit itemsWithinBasketFrom:[NSDate dateYesterday] through:[NSDate dateTomorrow]] count],

I have the following test in my unit test suite:

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]);

And the output from the build console is: Type mismatch -- A unit with no items should return 开发者_运维知识库nil when asked for items in basket within a date range. (count=0).

If count is 0, and I'm testing its equality against 0, then why do I get a type mismatch?

Thanks!


count returns NSUInteger which is unsigned int. You set the expected value as 0 which is int. Those types are different ones. Cast your 0 to NSUInteger like (NSUInteger)0 or use 0U.


IMO, the problem is not the count is 0 or not. What is the returned type of [[newUnit itemsInPlaceWithinDateRangeFrom:[NSDate dateYesterday] through:[NSDate dateTomorrow]] count]. Maybe your type is not correct (like double), then when you try to print it out, it appears to be 0. And because it can not compare int and double, it generates type mismatch. It is just my guess

0

精彩评论

暂无评论...
验证码 换一张
取 消