Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 单元测试失败——为什么?_Iphone_Unit Testing_Xcode - Fatal编程技术网

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