@Suppress
public void testIfScreenRotationHandledCorrectly() throws Exception {
requestFocus(mTeNumber);
sendKeys("1 0 0");
requestFocus(mBtnConvert);
sendKeys(KeyEvent.KEYCODE_ENTER);
String expectedTvValue = mTvResult.getText().toString();
String expectedTeValue = mTeNumber.getText().toString();
for(int i=0; i<=10; i++) {
if(i % 2 == 0) {
mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
//FIXME :: Fix this problem.
/*
* The problem here is that after screen rotation mActivity and all of our fields still refer to the old activity that we had and so assertEquals
* methods wrongly return true. So first we must renew our mActivity and all other references. The following solution does not solve our problem
* But currently I do not have enough time to solve this issue so I @Suppress it for now. For more information refer to:
* http://stackoverflow.com/questions/10982370/instrumentation-test-for-android-how-to-receive-new-activity-after-orientation
* For now I use Instrumentation.callActivityOnSaveInstanceState.
*/
mActivity.finish();
setActivity(null);
setUp();
getInstrumentation().waitForIdleSync();
assertEquals("TeNumber value is not valid after rotation", expectedTeValue, mTeNumber.getText().toString());
assertEquals("TvResult value is not valid after rotation",expectedTvValue, mTvResult.getText().toString());
}
}
KonvertorTests.java 文件源码
java
阅读 29
收藏 0
点赞 0
评论 0
项目:Tabdilak
作者:
评论列表
文章目录