Execute specific tests from the command line with Gradle
- Use Gradle to build the
androidTesttarget. - Use the Android Debug 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: <app_name>/build/reports/androidTests/connected/flavors/APPTEST.
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.