I was looking for a way to simulate SharedPreferences for a Robolectric-tested application. It seems that the suggested way to do this involves AndroidX, a separate testing framework, which needs to be added as a dependency:
testImplementation 'androidx.test:core:1.1.0'
Then the application context can be retrieved with ApplicationProvider.getApplicationContext(), and a SharedPreferences can be obtained from getSharedPreferences as usual.
No comments:
Post a Comment