我想单元测试自定义单元是否注册了tableView
。如何测试自定义单元格是否已使用tableView注册?
-(void)viewDidLoad
{
[super viewDidLoad];
UINib *nib = [UINib nibWithNibName:@"FTStatsCellView" bundle:nil];
[[self tableView] registerNib:nib forCellReuseIdentifier:@"FTStatsCellView"];
}
单元测试:
-(void)testIfCustomCellsAreRegisteredToTable
{
[viewController viewDidLoad];
FTStatsCellView *cell = [[viewController tableView] dequeueReusableCellWithIdentifier:@"FTStatsCellView"];
XCTAssertNotNil(cell, @"Custom cell FTStatsCellView is not registered with the table.");
}
测试失败并显示消息:
[FTStatsViewControllerTests testIfCustomCellsAreRegisteredToTable] 失败:在束无法加载NIB:“一个NSBundle (已加载)',名称为'FTStatsCellView'
有什么建议吗?感谢
更新
如果我点击该项目,从没有到应用程序更改test target
的目标,那么它的工作原理。
但是,这有一个应用程序在模拟器我要运行单元测试每次运行的副作用。
有什么建议吗?
您是否将笔尖包含在测试目标中? – Wain
看来我有一个类似的问题,因为在这里:http://stackoverflow.com/questions/1879247/why-cant-code-inside-unit-tests-find-bundle-resources但不知道如何将路径与'nibWithNibName'。 – Houman
Btw xib文件已经检查了测试目标成员资格。它包含在测试目标的'copy bundle resources'中。我卡住了...... – Houman