特定のアクションによってモーダル ビュー コントローラーが表示されることを示す統合テストを作成したいと考えています。ストーリーボードは 2 つのビュー コントローラーでセットアップされます。1 つはカスタム ViewController クラスで、もう 1 つはデフォルトの UIViewController クラスで、タイトルは「second」です。セグエは、識別子「modalsegue」でモーダルになるように設定されています。シミュレーターでアプリを実行すると見事に動作しますが、正しいテストを定義するのに苦労しています。
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)
私は何を間違っていますか?最初のメッセージを回避する簡単な方法はありますか?