我的意思是如何轮换活动:使用Espresso改变屏幕方向? [英] How to rotate activity, I mean: screen orientation change using Espresso?

查看:71
本文介绍了我的意思是如何轮换活动:使用Espresso改变屏幕方向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为使用Google的Espresso进行应用程序测试的测试标准之一是:

I have decided that one of the testing criteria for my application tests with Google's Espresso is:

旋转屏幕方向后,测试应保持活动"状态

Test should maintain Activity state after screen orientation rotation

使用Espresso时如何旋转屏幕?

How do I rotate the screen when using Espresso?


我尝试了以下Robotium代码(是的,我在我的Espresso测试中放置了Robotium代码,所以起诉我)


I have tried the following Robotium code (Yes I placed Robotium code in my Espresso test so sue me)

solo.setActivityOrientation(solo.LANDSCAPE);
solo.setActivityOrientation(solo.PORTRAIT);

但是当我在Espresso测试中运行该应用程序时,它会使应用程序崩溃.
有什么办法吗?

but It crashes the application when I run it within my Espresso test.
Is there any way to do this?

在此先感谢您的帮助

推荐答案

如果您的测试用例中只有活动",则可以执行以下操作:

If you have the only Activity in your test case, you can do:

@Rule
public ActivityTestRule<TestActivity> mActivityTestRule = new ActivityTestRule<>(TestActivity.class);

2.让您Activity并应用屏幕旋转.

2. Get you Activity and apply a screen rotation.

mActivityTestRule.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
mActivityTestRule.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

那是一块馅饼!

这篇关于我的意思是如何轮换活动:使用Espresso改变屏幕方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆