如何为这种“成功”场景编写测试用例?
if ([tblView.delegate respondsToSelector:@selector(tableView:viewForHeaderInSection:)]) {
...
}else{
...
}
我已经尝试通过在 swift 中创建以下模拟委托:
class MockTableViewDelegate:NSObject, UITableViewDelegate {
@objc func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 30
}
// MARK: Delegates
@objc func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return UIView()
}
}
代码:
mockTableView.delegate=MockTableViewDelegate()
print("delegate===\(mockTableView.delegate)")
它打印为零。我为数据源尝试过的相同模型,它正在返回数据源 obj。为什么代表返回零?以及如何测试这种情况?