如何使用Quick and Nimble编写测试用例以检查这段代码?
在ViewController中
for id in boxesArray {
if let box = Boxservice.shared.storeBoxes.size(id: id), box.size != nil {
availbleBoxesArray.append(box.size)
}
}
在测试用例文件中
context("When boxes array is not nil") {
let box = BoxSize()
box.size = "medium"
let storeBoxes = StoreBoxes.init()
storeBoxes.add(box)
beforeEach {
Boxservice.shared.storeBoxes = storeBoxes
viewController.fetchBoxSizes()
}
it("available boxes should not be nil") {
expect(viewController?.availbleBoxesArray).toNot(beNil()) // This test passes succesfully.
}
it("available boxes should contain given box size") {
expect(viewController?.availbleBoxesArray.first).to(contain(box)) // This test is failing.
}
}
代码覆盖率并未覆盖该代码段的顶部,并且无法快速,灵活地测试该部分。如何编写适当的测试用例以处理该用例。
非常感谢您的帮助。