It looks like you need to wrap around SharedPreferences, which provides your own general settings interface. For instance.
public interface PreferencesProvider { String getStringValue(String key); }
Regardless of your class being tested (e.g. Activity), you can use a specific implementation of PreferencesProvider that calls PreferenceManager.getDefaultSharedPreferences ... etc. In your test class, you can replace a fake specific implementation to return whatever you like for your tests.
Thus, your preference provider is separate from your application class, and testing becomes simple. In fact, your tests never require touching the actual prefs stored on your phone.
Putting this into action, however, requires some kind of dependency injection mechanism, such as RoboGuice.
source share