【问题标题】:Android Instrumentation Test for multiple screen sizes / layouts针对多种屏幕尺寸/布局的 Android Instrumentation 测试
【发布时间】:2016-03-21 20:28:05
【问题描述】:

我有一些屏幕在大屏幕上是分屏,但在小屏幕上是单屏,如下所述: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,而不是我设置所有套件。

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

【问题讨论】:

    标签: android android-testing android-espresso


    【解决方案1】:

    我使用以下 -

    /**
     * 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. Organizing them in Suites and running the suites.

    举例

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

    1. Annotating them with for example "@TabletTest" or "@PortraitOnly" and filtering them in a test run.

    举例

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

    【讨论】:

    • 感谢您花时间回答并提供这些链接。有时间请看更新块。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-20
    • 1970-01-01
    • 2014-10-22
    • 1970-01-01
    相关资源
    最近更新 更多