我想创建一个集成测试,它显示某个动作导致显示一个模态视图控制器。故事板设置了2个视图控制器,其中一个具有自定义ViewController类,第二个具有默认的UIViewController类和标题“second”。 segue设置为模态,标识符为“modalsegue”。在模拟器中运行应用程序效果出色,但我在定义正确的测试时遇到了很多问题。segues的自动化测试
ViewController.m:
@implementation ViewController
- (IBAction)handleActionByPerformingModalSegue {
[self performSegueWithIdentifier:@"modalsegue" sender:self];
}
@end
测试:
- (void)testActionCausesDisplayOfSecondViewController {
ViewController * vc =
[[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]
instantiateViewControllerWithIdentifier:@"ViewController"];
[vc handleActionByPerformingModalSegue];
STAssertEquals(vc.presentedViewController.title, @"second",
@"Title of presented view controller should be second but is %@",
vc.presentedViewController.title, nil);
}
运行下面的输出测试结果:
2013-06-23 17:38:44.164 SeguesRUs[15291:c07] Warning: Attempt to present <UIViewController: 0x7561370> on <ViewController: 0x7566590> whose view is not in the window hierarchy!
SeguesRUsTests.m:33: error: -[SeguesRUsTests testActionCausesDisplayOfSecondViewController] : '<00000000>' should be equal to '<9c210d07>': Title of presented view controller should be second but is (null)
我在做什么错?有没有简单的方法来避免第一条消息?
好,你应该切换到一个更高层次的框架将实际测试的用户界面,而不是内部的一些方法 - 弗兰克 - 黄瓜例如苹果的UI自动化。 – Sulthan