Is there a way of testing the save and restore state code of an activity programmatically ? I mean doing this :
How to test code built to save/restore Lifecycle of an A
You can rotate the screen and verify that the state is saved and restored properly.
private void rotateScreen() {
Context context = InstrumentationRegistry.getTargetContext();
int orientation
= context.getResources().getConfiguration().orientation;
Activity activity = activityRule.getActivity();
activity.setRequestedOrientation(
(orientation == Configuration.ORIENTATION_PORTRAIT) ?
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE :
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
Full example: http://blog.sqisland.com/2015/10/espresso-save-and-restore-state.html