I am writing espresso tests for my app and having difficulties clearing the app state, state gets saved and this affects other tests and brings flakiness to them.
I use intent rule for starting my activity:
@Rule
public final IntentsTestRule<MainActivity> mIntentsTestRule = newIntentsTestRule<>(MainActivity.class, true, false);
My setUp clears everything that I have access to: db, sharedPrefs, custom volatile config.
@Before
public void setUp() {
mSharedPrefManager.clear();
mAppConfig.clear();
mDatabasePersister.deleteDatabase();
}
Sadly I have issues with activity saved instance state, this brings flakiness to my tests since previous states are retained.
Is there a way to clear the saved instance states programmatically for each activity start?