我想創建一個集成測試,它顯示某個動作導致顯示一個模態視圖控制器。故事板設置了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