Running filtered androidTests from gradle command line

Parameters

The espresso test runner has some parameters which can be used from the gradle command line to filter tests.

Run all tests in the given package.

android.testInstrumentationRunnerArguments.package=[packagename]

Run all tests in the given test class.

android.testInstrumentationRunnerArguments.class=[classname]

Run an individual test method.

android.testInstrumentationRunnerArguments.class=[classname]#[testMethod]

Examples

Run all tests in a package.

./gradlew connectedTests -Pandroid.testInstrumentationRunnerArguments.package=com.example.app.userinterface

Run all tests in a class

./gradlew connectedTests -Pandroid.testInstrumentationRunnerArguments.class=com.example.app.userinterface.TestMainActivity

 Run an individual test method.

./gradlew connectedTests -Pandroid.testInstrumentationRunnerArguments.class=com.example.app.userinterface.TestMainActivity#testClickOk

Outputs

Test outputs are found in the module’s build/reports/androidTests/connected/ directory.

Other gradle tasks.

If you have other gradle tasks that run the connected android tests, you can pass the parameters to those too. For example, if you are generating jacoco coverage reports you can generate the report for just what you are working on. This can be done within the android studio “Run Configurations”.

Leave a Reply

Your email address will not be published. Required fields are marked *