EarlGrey 有没有办法让我自动重置应用程序?
Is there a way in EarlGrey for me to reset the application automatically?
假设我有以下应用程序结构:
[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 交互,在每个测试用例完成后将应用程序带回主屏幕。
在您的 App 委托中引入一个方法 resetApplicationForTesting
并从每个测试用例的 setUp 方法中调用它。 如果此逻辑需要与多个测试用例共享,请考虑创建一个由这些测试用例继承的 BaseTestClass。
在测试的设置方法中:
MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
[delegate resetApplicationForTesting];
假设我有以下应用程序结构:
[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 交互,在每个测试用例完成后将应用程序带回主屏幕。
在您的 App 委托中引入一个方法
resetApplicationForTesting
并从每个测试用例的 setUp 方法中调用它。 如果此逻辑需要与多个测试用例共享,请考虑创建一个由这些测试用例继承的 BaseTestClass。
在测试的设置方法中:
MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
[delegate resetApplicationForTesting];