如何使用 KIF 测试空 table?

How to test for an empty table using KIF?

我正在使用 KIF test framework。目前,我能够通过以下行检测到 table not 为空:

tester().waitForCellAtIndexPath(NSIndexPath(forRow: 0, inSection: 0), 
    inTableViewWithAccessibilityIdentifier: "My Table")

但是,我需要能够测试 table 是否完全为空。使用 KIF 实现此目的的最佳方法是什么?

想通了。您可以获取 table 然后对其执行您想要的任何操作:

//Helper function
extension KIFUITestActor {
    func waitForViewWithAccessibilityIdentifier(accessibilityIdentifier: String) -> UIView? {
        var view: UIView?
        self.waitForAccessibilityElement(nil, view: &view, withIdentifier: accessibilityIdentifier, tappable: false)
        return view
    }
}

if let myTable = tester().waitForViewWithAccessibilityIdentifier("My Table") as? UITableView {
    XCTAssertNil(myTable.cellForRowAtIndexPath(NSIndexPath(forRow: 0, inSection: 1)), "My Table should have been empty.")
}

由于 table 视图可以有 N 个服务于不同目的的部分,因此 KIF 尝试提供测试助手来检查 "empty table" 没有多大意义。

编辑:我添加了此答案中缺少的辅助函数定义