Running all tests listed in a file: adb shell am instrument -w -e testFile
/sdcard/tmp/testFile.txt com.android.foo/com.android.test.runner.AndroidJUnitRunner The file
should contain a list of line separated package names or test classes and optionally methods.
Valid package names consist of one or more java identifiers delimited by the '.' character, in
which the first character of the last identifier is not a capitalized letter. Valid class names
consist of one or more java identifiers delimited by the '.' character, in which the first
character of the last identifier is a capitalized letter. Valid method names are valid class
names with a '#' character and an additional java identifier appended to the end. (expected class
format: com.android.foo.FooClassName#testMethodName) (expected package format: com.android.foo)

Running all tests not listed in a file: adb shell am instrument -w -e notTestFile
/sdcard/tmp/notTestFile.txt com.android.foo/com.android.test.runner.AndroidJUnitRunner The file
should contain a list of line separated package names or test classes and optionally methods.
Valid package names consist of one or more java identifiers delimited by the '.' character, in
which the first character of the last identifier is not a capitalized letter. Valid class names
consist of one or more java identifiers delimited by the '.' character, in which the first
character of the last identifier is a capitalized letter. Valid method names are valid class
names with a '#' character and an additional java identifier appended to the end. (expected class
format: com.android.foo.FooClassName#testMethodName) (expected package format: com.android.foo)

If used with other options, the resulting test run will contain the intersection of the two
options. e.g. "-e size large -e annotation com.android.foo.MyAnnotation" will run only tests with
both the LargeTest and "com.android.foo.MyAnnotation" annotations.

As above, if used with other options, the resulting test run will contain the intersection of
the two options. e.g. "-e size large -e notAnnotation com.android.foo.MyAnnotation" will run
tests with the LargeTest annotation that do NOT have the "com.android.foo.MyAnnotation"
annotations.

Filter test run to tests without any of a list of annotations: adb shell am
instrument -w -e notAnnotation com.android.foo.MyAnnotation,com.android.foo.AnotherAnnotation
com.android.foo/androidx.test.runner.AndroidJUnitRunner

Filter test run to tests that pass all of a list of custom filter(s):
adb shell am instrument -w -e filter
com.android.foo.MyCustomFilter,com.android.foo.AnotherCustomFilter
com.android.foo/androidx.test.runner.AndroidJUnitRunner

A Filter class provided to the filter option must be public and must provide a
public constructor of one of the following patterns. They are searched in order and the first one
found is the one that is used.

<init>() - a no arguments constructor. This is for filters whose behavior is hard
coded.

<init>(Bundle bundle - accepts a Bundle that contains the options passed to
this instance. This is for filters whose behavior needs to be configured through additional
options to am instrument.

Filter test run to a shard of all tests, where numShards is an integer greater than 0 and
shardIndex is an integer between 0 (inclusive) and numShards (exclusive): adb shell am
instrument -w -e numShards 4 -e shardIndex 1
com.android.foo/androidx.test.runner.AndroidJUnitRunner

A RunnerBuilder class provided to the runnerBuilder option must be public and
must provide a public no-argument constructor.

To run in 'log only' mode -e log true This option will load and iterate through all
test classes and methods, but will bypass actual test execution. Useful for quickly obtaining
info on the tests to be executed by an instrumentation command.

To generate code coverage files (*.ec) that can be used by EMMA or JaCoCo: -e coverage
true Note: For this to work, your classes have to be instrumented offline (i.e. at build time) by
EMMA/JaCoCo. By default, the code coverage results file will be saved in a
/data/data//files/coverage.ec file, unless overridden by coverageFile flag (see below)

To specify one or more
RunListeners to observe the test run: -e listener
com.foo.Listener,com.foo.Listener2

To use the new order of
RunListeners during a test run: -e newRunListenerMode true

New order of listeners guarantee that user defined
RunListeners will be running before any of the default listeners defined in this
runner. Legacy order had those user defined listeners running after the default ones.

Note:The new order will become the default in the future.

To specify a custom ClassLoader to load the test class: -e
classLoader com.foo.CustomClassLoader

Set timeout (in milliseconds) that will be applied to each test: -e timeout_msec 5000

In order to make sure we are on the right track with each new release, the test runner
collects analytics. More specifically, it uploads a hash of the package name of the application
under test for each invocation. This allows us to measure both the count of unique packages using
this library as well as the volume of usage.

Public constructors

AndroidJUnitRunner

Public methods

finish

Ensures all activities launched in this instrumentation are finished before the instrumentation
exits.

Subclasses who override this method should do their finish processing and then call
super.finish to invoke this logic. Not waiting for all activities to finish() before exiting
can cause device wide instability.