Iphone 单元测试失败——为什么?
我的单元测试套件中有以下测试:Iphone 单元测试失败——为什么?,iphone,unit-testing,xcode,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)",
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]);
构建控制台的输出是:类型不匹配——当要求在日期范围内的篮子中输入项目时,没有项目的单元应该返回nil。(计数=0)
如果count是0,并且我正在测试它与0的相等性,那么为什么会得到类型不匹配
谢谢 IMO,问题不在于计数是否为0。返回的
[[newUnit itemsincplacewithindaterangefrom:[NSDate datedatebeday]到:[NSDate datetomory]]计数的类型是什么]
。可能您的类型不正确(如double),那么当您尝试打印出来时,它似乎是0。因为它不能比较int和double,所以会产生类型不匹配。这只是我的猜测计数
返回的是无符号整数
。将期望值设置为0,即int
。这些类型是不同的。将0强制转换为NSUInteger,如(NSUInteger)0
或使用0U
函数返回一个NSSet*
count
应该是NSSet上可用的方法。您可以尝试使用STAssertTrue,我将再次查找STASSERTQUALS