pla*_*mbo 24 testing instrumentation android screen-orientation uiinterfaceorientation
我正在使用ActivityInstrumentationTestCase2类为应用程序编写一些验收测试.我想在测试中引起方向更改,以确保发生许多事情.其中包括确保保留Activity状态,同时我还要确保使用适当的方向布局.
我知道我可以简单地测试onSaveInstanceState/onRestoreInstanceState/onPause/onResume/etc. 确保保留实例状态的方法.但是,我想知道是否存在导致方向改变事件的机制?
这是否会涉及注入某种运动事件来诱骗设备/仿真器认为它已被旋转,或者是否存在由仪器提供的实际方法?
谢谢和干杯!
And*_*wKS 49
实际上你根本不需要使用Robotium.事实上,如果您在调用时查看Robotium的来源
solo.setActivityOrientation(Solo.LANDSCAPE);
Run Code Online (Sandbox Code Playgroud)
是
myActivity = this.getActivity(); // In your setUp method()
...
myActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Run Code Online (Sandbox Code Playgroud)
正如AndrewKS所写,你可以使用
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
assertTrue(...);
Run Code Online (Sandbox Code Playgroud)
要求改变方向.但是旋转本身是异步执行的.要在方向更改后真正测试状态,您需要在请求后等待一小段时间:
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Thread.sleep(50); // depends on performance of the testing device/emulator
assertTrue(...);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15590 次 |
| 最近记录: |