3

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?

1
  • Did you try to finish your activity after each test? Instance state should not be stored for explicit finished activities.
    – nenick
    Mar 29, 2016 at 6:21

1 Answer 1

0

Issue was caused by a memory leak, so the activity was kept without properly clearing it, thanks for the effort, after resolving the leak espresso ran fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.