Skip to content

Hints and FAQ

Arnold Noronha edited this page May 16, 2016 · 3 revisions

Excluding non-screenshot tests from the run

Running gradle recordMode screenshotTests will run the task that was set in the gradle plugin extension field "screenshots", e.g. connectedAndroidTestTarget=connectedProdDebugAndroidTest. This will run all instrumentation tests instead of just the screenshot tests. One way to run only the screenshot tests is to set the DefaultProductFlavor field setTestInstrumentationRunnerArguments in your build.gradle file. This field allows us to set arguments for the am instrument command. In this example, we have our app package called com.example.app where our screenshot tests are in the package com.example.app.tests.screenshots.

android {
    defaultConfig {
        if (project.gradle.startParameter.taskNames.contains("screenshotTests")) {
            Map<String, String> map = new HashMap<String, String>();
            map.put("package", "com.example.app.tests.screenshots");
            setTestInstrumentationRunnerArguments map
        }
        ...
    }
    ...
}    

When running gradle recordMode/verifyMode screenshotTests, this statement will satisfy the if conditional and pass the argument package=com.example.app.tests.screenshots to the am instrument command, e.g. adb shell am instrument -w -e package com.example.app.tests.screenshots which will execute any test case class that are below this package.

Clone this wiki locally