gpt4 book ai didi

android - 自动化测试时如何改变屏幕方向?

转载 作者:行者123 更新时间:2023-11-29 02:15:33 24 4
gpt4 key购买 nike

我正在使用 ActivityInstrumentationTestCase2 测试我的 Android 应用程序,我需要测试屏幕方向更改是否正常工作。但是,我找不到任何方法来导致定向发生。我错过了什么?

最佳答案

查看此示例,其中我尝试扩展 Android ActivityInstrumentationTestsCase2 以使用不同的屏幕方向:iliasbartolini / AgileDayConferenceApp

基本上您需要更改资源配置。我在这里找到了这个例子: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关于如何使用它。

它实际上只检查 Activity 加载的横向布局和资源是否损坏:不知道是否有更好的方法。

And here the Portrait test

关于android - 自动化测试时如何改变屏幕方向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4263140/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com