0

I am running espresso tests and want to remove the LruCache on each test run.

I am able to do so for preferences:

    @Before
    @After
    public void clearSharedPrefs() {
        SharedPreferences settings = loginActivityActivityTestRule.getActivity().getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = settings.edit();
        editor.clear();
        editor.commit();
    }

Please let me know how can I do the same for LruCache?

Shubham
  • 2,627
  • 3
  • 20
  • 36
  • First of all, why don't you have two different methods setUp() and tearDown(), both annotated accordingly with @Before and @After? Second, I'm not familiar with LruCache, but I was looking a bit on android docs. It seems easy to clear it. – mbob Nov 02 '17 at 13:47
  • @mbob Yes I was able to do it,using the remove method of LruCache although I was initially looking for resetting the whole app for each test. – Shubham Nov 03 '17 at 05:11
  • By resetting the whole app, you mean clearing the cache like the user does from settings? If so -> https://stackoverflow.com/questions/23908189/clear-cache-in-android-application-programmatically – mbob Nov 03 '17 at 08:49

0 Answers0