开发者

How to change the screen orientation during automated testing?

开发者 https://www.devze.com 2023-01-26 09:28 出处:网络
I am testing my Android application using A开发者_Go百科ctivityInstrumentationTestCase2, and I need to test that the screen orientation change works correctly. However, I cannot find any way to cause

I am testing my Android application using A开发者_Go百科ctivityInstrumentationTestCase2, and I need to test that the screen orientation change works correctly. However, I cannot find any way to cause an orientation to occur. What am I missing?


Check this example where I tried extending Android ActivityInstrumentationTestsCase2 to use different screen orientations: iliasbartolini / AgileDayConferenceApp

Basically you need to change the Resources configuration. I found this example here: Tip for unit-testing: loading Resources for a specific screen orientation/

Resources res = getInstrumentation().getTargetContext().getResources();
Configuration oldResourcesConfiguration = res.getConfiguration();
Configuration newConfiguration = new Configuration(oldResourcesConfiguration);
newConfiguration.orientation = configurationOrientation;
res.updateConfiguration(newConfiguration, res.getDisplayMetrics());

Here is a dummy Landscape test example on how to use it.

It actually only checks that the Landscape layout and resources loaded by the activity are not broken: don't know if there are better ways to do it.

And here the Portrait test

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号