I have seen SharedPreferences.setInitialMockValues or something like that. Still, since SharedPreferences has become a legacy API and with the new SharedPreferencesAsync/SharedPreferencesWithCache API, I cannot find a way to create mocks for them for testing.