【问题标题】:iOS Unit Testing of Custom UITableViewCell自定义 UITableViewCell 的 iOS 单元测试
【发布时间】:2016-02-16 11:03:21
【问题描述】:

我正在对一个自定义UITableviewCell(TrasmitCell) 数据进行单元测试,我们在UITableviewCell、textLabel 和 DetailTextLabel 中有内置标签,而不是我创建了一个自定义单元格并显示在我的表格视图中。现在我想测试传递给该自定义单元格的数据。我能够获得内置方法 textLabel 和 DetailTextLabel 但我如何获得自定义单元格(TrasmitCell) 的内容。自定义单元格(TrasmitCell) 有两个标签和一个图像

- (void)testTableViewCellsHaveCorrectTextLabel {

NSIndexPath *rowIndex0 = [NSIndexPath indexPathForRow:0 inSection:0];

UITableViewCell *cell0 = [self.viewControllerUnderTest tableView:self.viewControllerUnderTest.tableView cellForRowAtIndexPath:rowIndex0];

XCTAssert([cell0.textLabel.text isEqualToString:@"abc"], @"ViewController under test is composed of a UITableView that has improperly initialized UITableViewCells");

//Instead of cell0.textLabel.text m looking for data from custom tableview cell objects
}

【问题讨论】:

    标签: ios objective-c uitableview unit-testing


    【解决方案1】:

    试试苹果 UI 测试——link

    你也可以试试KIF

    UI 测试 - 不是单元测试。您只能使用单元测试 (XCT) 来处理数据(例如,如果您计算输入数据并将结果保存在标签中)。

    【讨论】:

      猜你喜欢
      • 2018-02-25
      • 2011-11-05
      • 2023-01-16
      • 2012-10-05
      • 2015-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多