Greg Smalls
Greg Smalls

Reputation: 11

Unit Test Fails -- Why?

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!

Upvotes: 1

Views: 433

Answers (2)

dmitry747
dmitry747

Reputation: 593

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.

Upvotes: 3

vodkhang
vodkhang

Reputation: 18741

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

Upvotes: 0

Related Questions