簡體   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