伪代码,我觉得你的测试会是这样的:
// in setUp, grab a reference to your desired view controllers & buttons
// in the test method:
// press a tab (or whatever it takes) to navigate to the Results view
// press the button for the first result (using target/action or however you have it set up)
STAssertTrue([myNavigationController.visibleViewController isKindOfClass:[DetailViewController class]]);
STAssertTrue([(DetailViewController *)myNavigationController.visibleViewController result] == /*first result from earlier*/);
// in tearDown, do cleanup if necessary
如果这还不够,你应该张贴一些代码,所以我们可以帮助更容易。编号:setUp
的更多相关信息。我认为这是值得看的,从示例代码链接到您的实现:
- (void) setUp {
app_delegate = [[UIApplication sharedApplication] delegate];
calc_view_controller = app_delegate.calcViewController;
calc_view = calc_view_controller.view;
}
app_delegate
,和calc_view
是CalcApplicationTests
类的实例变量,这样他们就可以从任何-test...
方法中使用。作为应用程序控制器的本质,应用程序委托具有对主视图控制器的引用。我认为这是一个非常简单和理智的方式。
我没有任何代码后, - 但是这是非常有帮助,谢谢! – Simon
您可以添加一些关于如何获取控制器引用的详细信息吗? – Simon
我没有一吨的这方面的经验要么,但我会在大约一个多一点的信息进行编辑。 – jtbandes