繁体   English   中英

适用于多种屏幕尺寸/布局的Android Instrumentation Test

[英]Android Instrumentation Test for multiple screen sizes / layouts

我有一些在大屏幕上是分屏的屏幕,但在小屏幕上是单屏幕,如此处所述: http : //developer.android.com/training/basics/fragments/fragment-ui.html

我试图编写一个运行我的应用程序所有功能的测试用例,并且模拟了所有网络调用,依此类推。

我知道的唯一剩下的问题是,是否存在测试多种布局的正确方法。

现在,我需要使用要测试的配置在各种AVD上手动运行测试用例,并且我使用以下格式进行调用:

if( uiDevice.getDisplaySizeDp().x < 600) {
    // we are using the standard layout, so the fragment was opened on top of the stack, instead of side-by-side
    // press Back to get back to the list of objects
    pressBack();
}

我正在使用AndroidJUnit4android.support.test.runner.AndroidJUnitRunner运行Espresso测试。

问题是:是否有我可以与我的团队共享的标准/记录方法来处理不同的布局限定符: sw600dpw900dplandscape等。

或者,是否可以指定匹配限定符的设备要运行哪些测试用例?

根据drfrag01更新答案:

我想我正在寻找更多的东西,这些东西一旦跑步者在设备上启动,便能够自动选择要运行的测试用例。 我最好的情况可能是在其中添加注解@ SW600或@Normal,然后在设备上运行测试时,跳过@ SW600的小型电话,而不是我设置所有套件。

如果没有自定义的测试运行器,这似乎是不可能的。

我使用以下内容-

/**
 * Determine if the device is a tablet (i.e. it has a large screen).
 *
 * @param context The calling context.
 */

public static boolean isTablet(Context context) {
    return (context.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK)
            >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}


/**
 * Determine if the device is in landscape or portrait mode. Returns true for portrait, and false
 * for landscape.
 */
public static boolean isPortrait(Context context) {
    return context.getResources().getConfiguration().screenHeightDp > context.getResources().getConfiguration().screenWidthDp;
}

您可以过滤需要运行的测试用例

  1. 在套件中组织它们并运行套件。

例如

./gradlew -Pandroid.testInstrumentationRunnerArguments.class = com.mycompany.foo.test.Suites.PortraitFriendlyTestSuite connectedAndroidTest --info

  1. 用例如“ @TabletTest”或“ @PortraitOnly”注释它们,并在测试运行中对其进行过滤。

例如

./gradlew -Pandroid.testInstrumentationRunnerArguments.annotation = com.mycompany.foo.Annotations.PortraitOnly connectedAndroidTest --info

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM