Execute specific tests from the command line with Gradle
Follow these instructions to build the application, resolve dependencies, run the tests in the specified class on a connected
Androiddevice, and record the results.
- Change the directory to samples/<app_name>.
- Run the following command:./gradlew connectedAppTestDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=<className>Replace<classname>with the name of your class.
You can also run a specific test manually using the following method:
- UseGradleto build theandroidTesttarget.
- Use theAndroidDebug Bridge (ADB) tool to install the app from the resulting .apk file. You can choose to uninstall any existing app first or to install as an upgrade.
- Execute specific test suites or individual tests using the ADB tool, with a command such as:adb shell am instrument -w -e debug false -e class <packageName>.<className> <packageName>.test/testRunnerReplace<packagename>and<classname>with values for your app and class.
Test results are written to the following sub-directory:
You can save test results using a continuous integration system. You can also use a JUnit plug-in to display the test results in a readable form, to send email messages to project members, or to take other common continuous integration actions.
For more information about running tests using the command line, see Android Studio: Test from the command line.