Say I have the following app structure:
[View Controller 1] -> tap on next button
[View Controller 2] -> Check for Title
[[EarlGrey selectElementWithMatcher:grey_text(@"Next Button")]
[[EarlGrey selectElementWithMatcher:grey_text(@"Screen Title")]
[View Controller 3]
[View Controller 2]
As with any xctest the app is not restarted and remains in the same state that the previous test left it. You would require to reset app state explicitly in either the tearDown or setUp of the test case. You can:
Write UI interactions that takes the App back to the main screen after each test case completes.
Introduce a method
resetApplicationForTesting in your App delegate and invoke that from the setUp method of each test case. If this logic needs to be shared with multiple test cases, consider creating a BaseTestClass which these tests cases inherit.
In the test's setUp method:
MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate]; [delegate resetApplicationForTesting];