我正在使用XCtest来测试视图的标题.试着养成先写测试的习惯.设置看起来像
- (void)setUp { [super setUp]; self.appDelegate = [[UIApplication sharedApplication] delegate]; self.tipViewController = self.appDelegate.tipViewController; self.tipView = self.tipViewController.view; self.settingsViewController = self.appDelegate.settingsViewController; self.settingsView = self.settingsViewController.view; }
问题是"settingsViewController".我有两个实际测试功能:
- (void) testTitleOfMainView{ XCTAssertTrue([self.tipViewController.title isEqualToString:@"Tip Calculator"], @"The title should be Tip Calculator"); //why does this not work? // XCTAssertEqual(self.tipViewController.title, @"Tip Calculator", @"The title should be Tip Calculator"); } - (void) testTitleOfSettingsView{ //make the setttings view visible [self.tipViewController onSettingsButton]; //test the title XCTAssertTrue([self.settingsViewController.title isEqualToString:@"Settings"], @"The title should be Settings"); }
"testTitleOfMainView"有效.但是"testTitleOfSettingsView失败,因为self.settingsViewController是nil.我可以理解为什么.视图还没有初始化.所以我尝试将消息发送到主控制器,使settignscontroller在视图中
[self.tipViewController onSettingsButton];
settingsController仍为零.我应该使用嘲笑吗?有人建议我用另一个问题 xctest - 如何测试按钮按下时是否加载新视图
我应该将设置视图子类化并手动启动吗?谢谢.