Providing test data for SharedPreferences for Robolectric

后端 未结 4 1026
醉梦人生
醉梦人生 2020-12-13 08:40

Just started to use Robolectric and it seems to be pretty much what I need. However, I\'ve hit a bit of a roadblock with regards to the use of SharedPreferences.

I h

4条回答
  •  醉梦人生
    2020-12-13 09:05

    Robolectric 3.1 SNAPSHOT solution that works for me... and may work for you

        Context context = RuntimeEnvironment.application.getApplicationContext();
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
        sharedPreferences.edit().putBoolean("useOnlyOnWifi", false).commit();
    

    I use this snippet of code for only testing on wifi

提交回复
热议问题