When writing an Android test JUnit rule, is there ...
# android
s
When writing an Android test JUnit rule, is there a good way to write to SharedPreferences in it? Writing to SharedPreferences requires a Context
😶 6
e
if you can't fake out your Android dependencies, you'll need to use Robolectric or instrumentation test
s
this is for an instrumentation test
i want to set a state by setting some keys in shared preferences, and I'd prefer to do so using a rule
c
@Steve
SharedPreferences
is just an interface. It's not that much work to write your own implementation of it which is backed by
MutableMap<String, Any?>
, and then just dependency-inject that in-memory instance. I'd share code, but ours lives in the closed source portion of our app.