假设我具有以下应用程序结构:
[View Controller 1] -> tap on next button
[View Controller 2] -> Check for Title
在EarlGrey中,我通过执行以下操作定义了此测试:
[[EarlGrey selectElementWithMatcher:grey_text(@"Next Button")]
performAction:grey_tap()]
[[EarlGrey selectElementWithMatcher:grey_text(@"Screen Title")]
assertWithMatcher:grey_sufficientlyVisible()];
但是现在,当我要测试时[View Controller 3]
,我注意到该应用程序仍处于启动状态[View Controller 2]
。是否有我遗漏的电话可以使我返回第一个屏幕或重置应用程序以进行下一个测试?
与任何xctest一样,该应用程序不会重新启动,并保持与之前的测试相同的状态。您可能需要在测试用例的tearDown或setUp中显式重置应用程序状态。你可以:
完成每个测试用例后,编写可将应用程序带回主屏幕的UI交互。
resetApplicationForTesting
在您的App委托中引入一个方法,并从每个测试用例的setUp方法中调用该方法。如果此逻辑需要与多个测试用例共享,请考虑创建一个由这些测试用例继承的BaseTestClass。
在测试的setUp方法中:
MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
[delegate resetApplicationForTesting];
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句