【问题标题】:How to test for an empty table using KIF?如何使用 KIF 测试空表?
【发布时间】:2015-04-03 15:40:12
【问题描述】:

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

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

但是,我需要能够测试一个表是否完全为空。使用 KIF 完成此任务的最佳方法是什么?

【问题讨论】:

    标签: ios uitableview kif


    【解决方案1】:

    想通了。您可以抓住桌子,然后对它执行任何您想要的操作:

    //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.")
    }
    

    由于表视图可以有 N 个用于不同目的的部分,因此 KIF 尝试提供测试助手来检查“空表”没有多大意义。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-03
      • 1970-01-01
      • 2014-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-21
      • 2015-12-01
      相关资源
      最近更新 更多