I have an issue regarding unit testing android orientation shifts. I have both Portrait and Landscape supported in my application and I have to test if the views hierarchy is correctly drawn when the orientation changes.
I have created two test methods to check this, and I have something like this:
public void testOnCreate() throws Exception {
//Check all the activity components
assertNotNull(activity);
assertNotNull(application);
//Check if the rights components are available on the screen
assertNotNull(LayoutInflater.from(activity));
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
testOrientationPortrait();
}
On this particular case the tests pass, and the view hierarchy is drawn correctly. But when I try to test the landscape using:
public void testOrientationChange() throws Exception {
assertNotNull(activity);
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
//Check if the rights components are available on the screen
assertNotNull(LayoutInflater.from(activity));
testOrientationLandscape();
}
The orientation changes, but the view hierarchy fails, because views have the attributes from portrait.
Any ideas how to fix this?
Thanks, Ark