Updated #1: more info added to the end of this post
I\'m new to Android development and testing.
I have three Espresso tests. First test passes, but the
I found a workaround. I added code that hits back button multiple times in the tearDown() method to close all previously opened activities. Unfortunately I didn't found another method how to close all opened activities in Espresso. Robotium has a very convenient method for that purpose solo.finishOpenedActivities().
public void tearDown() throws Exception {
Log.d(TAG, "TEARDOWN");
goBackN();
super.tearDown();
}
private void goBackN() {
final int N = 10; // how many times to hit back button
try {
for (int i = 0; i < N; i++)
Espresso.pressBack();
} catch (com.google.android.apps.common.testing.ui.espresso.NoActivityResumedException e) {
Log.e(TAG, "Closed all activities", e);
}
}