# AndroidJUnitRunner

Artifact: [androidx.test:runner](https://developer.android.com/jetpack/androidx/releases/test) [View Source](https://cs.android.com/search?q=file:androidx/test/runner/AndroidJUnitRunner.java+class:androidx.test.runner.AndroidJUnitRunner)

*** ** * ** ***


```
public class AndroidJUnitRunner extends MonitoringInstrumentation
```

<br />

|---|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) ||||
| ↳ | [android.app.Instrumentation](https://developer.android.com/reference/android/app/Instrumentation.html) |||
|   | ↳ | [androidx.test.runner.MonitoringInstrumentation](https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation) ||
|   |   | ↳ | [androidx.test.runner.AndroidJUnitRunner](https://developer.android.com/reference/androidx/test/runner/AndroidJUnitRunner) |

Known direct subclasses [AndroidBenchmarkRunner](https://developer.android.com/reference/androidx/benchmark/junit4/AndroidBenchmarkRunner)

|---|---|
| `https://developer.android.com/reference/androidx/benchmark/junit4/AndroidBenchmarkRunner` | Instrumentation runner for benchmarks, used to increase stability of measurements and minimize interference. |

*** ** * ** ***

An `https://developer.android.com/reference/android/app/Instrumentation.html` that runs JUnit3 and JUnit4 tests against an Android package (application).

Based on and replacement for `https://developer.android.com/reference/android/test/InstrumentationTestRunner.html`. Supports a superset of `https://developer.android.com/reference/android/test/InstrumentationTestRunner.html` features, while maintaining command/output format compatibility with that class.

### Typical Usage

Write JUnit3 style s and/or JUnit4 style `https://junit.org/junit4/javadoc/latest/org/junit/Test.html`s that perform tests against the classes in your package. Make use of the `https://developer.android.com/reference/androidx/test/InstrumentationRegistry` if needed.

In an appropriate AndroidManifest.xml, define an instrumentation with android:name set to `https://developer.android.com/reference/androidx/test/runner/AndroidJUnitRunner` and the appropriate android:targetPackage set.

#### Execution options:

**Running all tests:** adb shell am instrument -w com.android.foo/androidx.test.runner.AndroidJUnitRunner

**Running all tests in a class:** adb shell am instrument -w -e class com.android.foo.FooTest com.android.foo/androidx.test.runner.AndroidJUnitRunner

**Running a single test:** adb shell am instrument -w -e class com.android.foo.FooTest#testFoo com.android.foo/androidx.test.runner.AndroidJUnitRunner

**Running all tests in multiple classes:** adb shell am instrument -w -e class com.android.foo.FooTest,com.android.foo.TooTest com.android.foo/androidx.test.runner.AndroidJUnitRunner

**Running all tests except those in a particular class:** adb shell am instrument -w -e notClass com.android.foo.FooTest com.android.foo/androidx.test.runner.AndroidJUnitRunner

**Running all but a single test:** adb shell am instrument -w -e notClass com.android.foo.FooTest#testFoo com.android.foo/androidx.test.runner.AndroidJUnitRunner

**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) If -e useTestStorageService is also provided, the testfile will be converted to a relative path and retrieved from

**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 -e useTestStorageService is also provided, the testfile will be converted to a relative path and retrieved from

**Running all tests in a java package:** adb shell am instrument -w -e package com.android.foo.bar com.android.foo/androidx.test.runner.AndroidJUnitRunner

**Running all tests except a particular package:** adb shell am instrument -w -e notPackage com.android.foo.bar com.android.foo/androidx.test.runner.AndroidJUnitRunner

**Running all tests matching a given regular expression:** adb shell am instrument -w -e tests_regex BarTest.\* com.android.foo/androidx.test.runner.AndroidJUnitRunner

**To debug your tests, set a break point in your code and pass:** -e debug true

**Running a specific test size i.e. annotated with `https://developer.android.com/reference/androidx/test/filters/SmallTest` or `https://developer.android.com/reference/androidx/test/filters/MediumTest` or `https://developer.android.com/reference/androidx/test/filters/LargeTest`:** adb shell am instrument -w -e size \[small\|medium\|large\] com.android.foo/androidx.test.runner.AndroidJUnitRunner

**Filter test run to tests with given annotation:** adb shell am instrument -w -e annotation com.android.foo.MyAnnotation com.android.foo/androidx.test.runner.AndroidJUnitRunner

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 `https://developer.android.com/reference/androidx/test/filters/LargeTest` and "com.android.foo.MyAnnotation" annotations.

**Filter test run to tests *with all* annotations in a list:** adb shell am instrument -w -e annotation com.android.foo.MyAnnotation,com.android.foo.AnotherAnnotation com.android.foo/androidx.test.runner.AndroidJUnitRunner

**Filter test run to tests *without* given annotation:** adb shell am instrument -w -e notAnnotation com.android.foo.MyAnnotation com.android.foo/androidx.test.runner.AndroidJUnitRunner

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 `https://developer.android.com/reference/androidx/test/filters/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 `https://junit.org/junit4/javadoc/latest/org/junit/runner/manipulation/Filter.html`:** adb shell am instrument -w -e filter com.android.foo.MyCustomFilter,com.android.foo.AnotherCustomFilter com.android.foo/androidx.test.runner.AndroidJUnitRunner

A `https://junit.org/junit4/javadoc/latest/org/junit/runner/manipulation/Filter.html` 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.

1. `<init>()` - a no arguments constructor. This is for filters whose behavior is hard coded.
2. `<init>(Bundle bundle` - accepts a `https://developer.android.com/reference/android/os/Bundle.html` 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

**Use custom `https://junit.org/junit4/javadoc/latest/org/junit/runners/model/RunnerBuilder.html` to run test classes:** adb shell am instrument -w -e runnerBuilder com.android.foo.MyCustomBuilder,com.android.foo.AnotherCustomBuilder com.android.foo/androidx.test.runner.AndroidJUnitRunner

A `https://junit.org/junit4/javadoc/latest/org/junit/runners/model/RunnerBuilder.html` 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 EMMA or JaCoCo code coverage results file path:** -e coverage true -e coverageFile /sdcard/myFile.ec

**To specify one or more `https://junit.org/junit4/javadoc/latest/org/junit/runner/notification/RunListener.html`s to observe the test run:** -e listener com.foo.Listener,com.foo.Listener2

**To use the new order of `https://junit.org/junit4/javadoc/latest/org/junit/runner/notification/RunListener.html`s during a test run:** -e newRunListenerMode true

New order of listeners guarantee that user defined `https://junit.org/junit4/javadoc/latest/org/junit/runner/notification/RunListener.html`s 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.

`https://junit.org/junit4/javadoc/latest/org/junit/runner/notification/RunListener.html` can also be specified via `https://developer.android.com/reference/java/util/ServiceLoader.html` metadata.

**To specify a custom `https://developer.android.com/reference/java/lang/ClassLoader.html` to load the test class:** -e classLoader com.foo.CustomClassLoader

**Deprecated: Set timeout (in milliseconds) that will be applied to each test:** -e timeout_msec 5000 -e timeout essentially reuses the deprecated @Test(timeout) functionality. Use junit's Timeout Rule instead.

Supported for both JUnit3 and JUnit4 style tests. For JUnit3 tests, this flag is the only way to specify timeouts. For JUnit4 tests, this flag is only supported when using the the `https://developer.android.com/reference/androidx/test/ext/junit/runners/AndroidJUnit4` runner. It overrides timeouts specified via `https://junit.org/junit4/javadoc/latest/org/junit/rules/Timeout.html`. Please note that in JUnit4 `https://junit.org/junit4/javadoc/latest/org/junit/Test.html#timeout--` annotation will take precedence over both, this flag and `https://junit.org/junit4/javadoc/latest/org/junit/rules/Timeout.html` rule.

**(Beta)To specify a custom `https://developer.android.com/reference/androidx/test/runner/screenshot/ScreenCaptureProcessor` to use when processing a `https://developer.android.com/reference/androidx/test/runner/screenshot/ScreenCapture` produced by `https://developer.android.com/reference/androidx/test/runner/screenshot/Screenshot#capture()`**: -e screenCaptureProcessors com.foo.Processor,com.foo.Processor2

If no `https://developer.android.com/reference/androidx/test/runner/screenshot/ScreenCaptureProcessor` is provided then the `https://developer.android.com/reference/androidx/test/runner/screenshot/BasicScreenCaptureProcessor` is used. If one or more are provided the `https://developer.android.com/reference/androidx/test/runner/screenshot/BasicScreenCaptureProcessor` is not used unless it is one of the ones provided.

**(Beta) To specify a remote static method for the runner to attempt to call reflectively:** adb shell am instrument -w -e remoteMethod com.foo.bar#init

**Note:** The method must be static. Usually used to initiate a remote testing client that depends on the runner (e.g. Espresso).

**All arguments can also be specified in the in the AndroidManifest via a meta-data tag:**

eg. using listeners:

```
<instrumentation
   android:name="androidx.test.runner.AndroidJUnitRunner"
   android:targetPackage="com.foo.Bar">
   <meta-data
       android:name="listener"
       android:value="com.foo.Listener,com.foo.Listener2" />
</instrumentation>
```
Arguments specified via shell will override manifest specified arguments.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/test/runner/AndroidJUnitRunner#AndroidJUnitRunner()()` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/test/runner/AndroidJUnitRunner#onCreate(android.os.Bundle)(https://developer.android.com/reference/android/os/Bundle.html arguments)` Sets up lifecycle monitoring, and argument registry. |
| `boolean` | `https://developer.android.com/reference/androidx/test/runner/AndroidJUnitRunner#onException(java.lang.Object,java.lang.Throwable)(https://developer.android.com/reference/java/lang/Object.html obj, https://developer.android.com/reference/java/lang/Throwable.html e)` |
| `void` | `https://developer.android.com/reference/androidx/test/runner/AndroidJUnitRunner#onStart()()` This implementation of onStart() will guarantee that the Application's onCreate method has completed when it returns. |
| `void` | `https://developer.android.com/reference/androidx/test/runner/AndroidJUnitRunner#sendStatus(int,android.os.Bundle)(int resultCode, https://developer.android.com/reference/android/os/Bundle.html results)` |

### Inherited Constants

From [android.app.Instrumentation](https://developer.android.com/reference/android/app/Instrumentation.html) `static final https://developer.android.com/reference/java/lang/String.html` `https://developer.android.com/reference/android/app/Instrumentation.html#REPORT_KEY_IDENTIFIER = "id"` `static final https://developer.android.com/reference/java/lang/String.html` `https://developer.android.com/reference/android/app/Instrumentation.html#REPORT_KEY_STREAMRESULT = "stream"`

### Inherited methods

From [android.app.Instrumentation](https://developer.android.com/reference/android/app/Instrumentation.html) `https://developer.android.com/reference/android/os/TestLooperManager.html` `https://developer.android.com/reference/android/app/Instrumentation.html#acquireLooperManager(android.os.Looper)(https://developer.android.com/reference/android/os/Looper.html looper)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#addMonitor(android.app.Instrumentation.ActivityMonitor)(https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor.html monitor)` `https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor.html` `https://developer.android.com/reference/android/app/Instrumentation.html#addMonitor(android.content.IntentFilter, android.app.Instrumentation.ActivityResult, boolean)(
https://developer.android.com/reference/android/content/IntentFilter.html filter,
https://developer.android.com/reference/android/app/Instrumentation.ActivityResult.html result,
boolean block
)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#addResults(android.os.Bundle)(https://developer.android.com/reference/android/os/Bundle.html results)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#callActivityOnCreate(android.app.Activity, android.os.Bundle)(https://developer.android.com/reference/android/app/Activity.html activity, https://developer.android.com/reference/android/os/Bundle.html icicle)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#callActivityOnDestroy(android.app.Activity)(https://developer.android.com/reference/android/app/Activity.html activity)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#callActivityOnNewIntent(android.app.Activity, android.content.Intent)(https://developer.android.com/reference/android/app/Activity.html activity, https://developer.android.com/reference/android/content/Intent.html intent)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#callActivityOnPause(android.app.Activity)(https://developer.android.com/reference/android/app/Activity.html activity)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#callActivityOnPictureInPictureRequested(android.app.Activity)(https://developer.android.com/reference/android/app/Activity.html activity)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#callActivityOnPostCreate(android.app.Activity, android.os.Bundle)(https://developer.android.com/reference/android/app/Activity.html activity, https://developer.android.com/reference/android/os/Bundle.html savedInstanceState)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#callActivityOnRestart(android.app.Activity)(https://developer.android.com/reference/android/app/Activity.html activity)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#callActivityOnRestoreInstanceState(android.app.Activity, android.os.Bundle)(
https://developer.android.com/reference/android/app/Activity.html activity,
https://developer.android.com/reference/android/os/Bundle.html savedInstanceState
)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#callActivityOnResume(android.app.Activity)(https://developer.android.com/reference/android/app/Activity.html activity)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#callActivityOnSaveInstanceState(android.app.Activity, android.os.Bundle)(https://developer.android.com/reference/android/app/Activity.html activity, https://developer.android.com/reference/android/os/Bundle.html outState)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#callActivityOnStart(android.app.Activity)(https://developer.android.com/reference/android/app/Activity.html activity)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#callActivityOnStop(android.app.Activity)(https://developer.android.com/reference/android/app/Activity.html activity)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#callActivityOnUserLeaving(android.app.Activity)(https://developer.android.com/reference/android/app/Activity.html activity)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#callApplicationOnCreate(android.app.Application)(https://developer.android.com/reference/android/app/Application.html app)` `boolean` `https://developer.android.com/reference/android/app/Instrumentation.html#checkMonitorHit(android.app.Instrumentation.ActivityMonitor, int)(https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor.html monitor, int minHits)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#endPerformanceSnapshot()()` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#finish(int, android.os.Bundle)(int resultCode, https://developer.android.com/reference/android/os/Bundle.html results)` `https://developer.android.com/reference/android/os/Bundle.html` `https://developer.android.com/reference/android/app/Instrumentation.html#getAllocCounts()()` `https://developer.android.com/reference/android/os/Bundle.html` `https://developer.android.com/reference/android/app/Instrumentation.html#getBinderCounts()()` `https://developer.android.com/reference/android/content/ComponentName.html` `https://developer.android.com/reference/android/app/Instrumentation.html#getComponentName()()` `https://developer.android.com/reference/android/content/Context.html` `https://developer.android.com/reference/android/app/Instrumentation.html#getContext()()` `https://developer.android.com/reference/java/lang/String.html` `https://developer.android.com/reference/android/app/Instrumentation.html#getProcessName()()` `https://developer.android.com/reference/android/content/Context.html` `https://developer.android.com/reference/android/app/Instrumentation.html#getTargetContext()()` `https://developer.android.com/reference/android/app/UiAutomation.html` `https://developer.android.com/reference/android/app/Instrumentation.html#getUiAutomation()()` `boolean` `https://developer.android.com/reference/android/app/Instrumentation.html#invokeContextMenuAction(android.app.Activity, int, int)(https://developer.android.com/reference/android/app/Activity.html targetActivity, int id, int flag)` `boolean` `https://developer.android.com/reference/android/app/Instrumentation.html#invokeMenuActionSync(android.app.Activity, int, int)(https://developer.android.com/reference/android/app/Activity.html targetActivity, int id, int flag)` `boolean` `https://developer.android.com/reference/android/app/Instrumentation.html#isProfiling()()` `https://developer.android.com/reference/android/app/Activity.html` `https://developer.android.com/reference/android/app/Instrumentation.html#newActivity(java.lang.Class&lt;?&gt;, android.content.Context, android.os.IBinder, android.app.Application, android.content.Intent, android.content.pm.ActivityInfo, java.lang.CharSequence, android.app.Activity, java.lang.String, java.lang.Object)(
https://developer.android.com/reference/java/lang/Class.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?> clazz,
https://developer.android.com/reference/android/content/Context.html context,
https://developer.android.com/reference/android/os/IBinder.html token,
https://developer.android.com/reference/android/app/Application.html application,
https://developer.android.com/reference/android/content/Intent.html intent,
https://developer.android.com/reference/android/content/pm/ActivityInfo.html info,
https://developer.android.com/reference/java/lang/CharSequence.html title,
https://developer.android.com/reference/android/app/Activity.html parent,
https://developer.android.com/reference/java/lang/String.html id,
https://developer.android.com/reference/java/lang/Object.html lastNonConfigurationInstance
)` `static https://developer.android.com/reference/android/app/Application.html` `https://developer.android.com/reference/android/app/Instrumentation.html#newApplication(java.lang.Class&lt;?&gt;, android.content.Context)(https://developer.android.com/reference/java/lang/Class.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?> clazz, https://developer.android.com/reference/android/content/Context.html context)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#onCreate(android.os.Bundle)(https://developer.android.com/reference/android/os/Bundle.html arguments)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#onDestroy()()` `boolean` `https://developer.android.com/reference/android/app/Instrumentation.html#onException(java.lang.Object, java.lang.Throwable)(https://developer.android.com/reference/java/lang/Object.html obj, https://developer.android.com/reference/java/lang/Throwable.html e)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#onStart()()` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#removeMonitor(android.app.Instrumentation.ActivityMonitor)(https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor.html monitor)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#resetInTouchMode()()` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#runOnMainSync(java.lang.Runnable)(https://developer.android.com/reference/java/lang/Runnable.html runner)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#sendCharacterSync(int)(int keyCode)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#sendKeyDownUpSync(int)(int keyCode)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#sendKeySync(android.view.KeyEvent)(https://developer.android.com/reference/android/view/KeyEvent.html event)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#sendPointerSync(android.view.MotionEvent)(https://developer.android.com/reference/android/view/MotionEvent.html event)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#sendStringSync(java.lang.String)(https://developer.android.com/reference/java/lang/String.html text)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#sendTrackballEventSync(android.view.MotionEvent)(https://developer.android.com/reference/android/view/MotionEvent.html event)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#setAutomaticPerformanceSnapshots()()` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#setInTouchMode(boolean)(boolean inTouch)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#start()()` `https://developer.android.com/reference/android/app/Activity.html` `https://developer.android.com/reference/android/app/Instrumentation.html#startActivitySync(android.content.Intent)(https://developer.android.com/reference/android/content/Intent.html intent)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#startAllocCounting()()`

**This method is deprecated.**
`void` `https://developer.android.com/reference/android/app/Instrumentation.html#startPerformanceSnapshot()()` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#startProfiling()()` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#stopAllocCounting()()`

**This method is deprecated.**
`void` `https://developer.android.com/reference/android/app/Instrumentation.html#stopProfiling()()` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#waitForIdle(java.lang.Runnable)(https://developer.android.com/reference/java/lang/Runnable.html recipient)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#waitForIdleSync()()` `https://developer.android.com/reference/android/app/Activity.html` `https://developer.android.com/reference/android/app/Instrumentation.html#waitForMonitor(android.app.Instrumentation.ActivityMonitor)(https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor.html monitor)` `https://developer.android.com/reference/android/app/Activity.html` `https://developer.android.com/reference/android/app/Instrumentation.html#waitForMonitorWithTimeout(android.app.Instrumentation.ActivityMonitor, long)(
https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor.html monitor,
long timeOut
)` From [androidx.test.runner.MonitoringInstrumentation](https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation) `void` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#callActivityOnCreate(android.app.Activity,android.os.Bundle)(https://developer.android.com/reference/android/app/Activity.html activity, https://developer.android.com/reference/android/os/Bundle.html bundle)` `void` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#callActivityOnCreate(android.app.Activity,android.os.Bundle,android.os.PersistableBundle)(
https://developer.android.com/reference/android/app/Activity.html activity,
https://developer.android.com/reference/android/os/Bundle.html bundle,
https://developer.android.com/reference/android/os/PersistableBundle.html persistentState
)` `void` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#callActivityOnDestroy(android.app.Activity)(https://developer.android.com/reference/android/app/Activity.html activity)` `void` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#callActivityOnPause(android.app.Activity)(https://developer.android.com/reference/android/app/Activity.html activity)` `void` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#callActivityOnRestart(android.app.Activity)(https://developer.android.com/reference/android/app/Activity.html activity)` `void` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#callActivityOnResume(android.app.Activity)(https://developer.android.com/reference/android/app/Activity.html activity)` `void` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#callActivityOnStart(android.app.Activity)(https://developer.android.com/reference/android/app/Activity.html activity)` `void` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#callActivityOnStop(android.app.Activity)(https://developer.android.com/reference/android/app/Activity.html activity)` `void` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#callApplicationOnCreate(android.app.Application)(https://developer.android.com/reference/android/app/Application.html app)` `void` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#dumpThreadStateToOutputs(java.lang.String)(https://developer.android.com/reference/java/lang/String.html outputFileName)` `void` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#execStartActivities(android.content.Context,android.os.IBinder,android.os.IBinder,android.app.Activity,android.content.Intent[],android.os.Bundle)(
https://developer.android.com/reference/android/content/Context.html who,
https://developer.android.com/reference/android/os/IBinder.html contextThread,
https://developer.android.com/reference/android/os/IBinder.html token,
https://developer.android.com/reference/android/app/Activity.html target,
Intent[] intents,
https://developer.android.com/reference/android/os/Bundle.html options
)` `https://developer.android.com/reference/android/app/Instrumentation.ActivityResult.html` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#execStartActivity(android.content.Context,android.os.IBinder,android.os.IBinder,android.app.Activity,android.content.Intent,int)(
https://developer.android.com/reference/android/content/Context.html who,
https://developer.android.com/reference/android/os/IBinder.html contextThread,
https://developer.android.com/reference/android/os/IBinder.html token,
https://developer.android.com/reference/android/app/Activity.html target,
https://developer.android.com/reference/android/content/Intent.html intent,
int requestCode
)` `https://developer.android.com/reference/android/app/Instrumentation.ActivityResult.html` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#execStartActivity(android.content.Context,android.os.IBinder,android.os.IBinder,android.app.Activity,android.content.Intent,int,android.os.Bundle)(
https://developer.android.com/reference/android/content/Context.html who,
https://developer.android.com/reference/android/os/IBinder.html contextThread,
https://developer.android.com/reference/android/os/IBinder.html token,
https://developer.android.com/reference/android/app/Activity.html target,
https://developer.android.com/reference/android/content/Intent.html intent,
int requestCode,
https://developer.android.com/reference/android/os/Bundle.html options
)` `https://developer.android.com/reference/android/app/Instrumentation.ActivityResult.html` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#execStartActivity(android.content.Context,android.os.IBinder,android.os.IBinder,android.app.Fragment,android.content.Intent,int,android.os.Bundle)(
https://developer.android.com/reference/android/content/Context.html who,
https://developer.android.com/reference/android/os/IBinder.html contextThread,
https://developer.android.com/reference/android/os/IBinder.html token,
https://developer.android.com/reference/android/app/Fragment.html target,
https://developer.android.com/reference/android/content/Intent.html intent,
int requestCode,
https://developer.android.com/reference/android/os/Bundle.html options
)` `https://developer.android.com/reference/android/app/Instrumentation.ActivityResult.html` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#execStartActivity(android.content.Context,android.os.IBinder,android.os.IBinder,java.lang.String,android.content.Intent,int,android.os.Bundle)(
https://developer.android.com/reference/android/content/Context.html who,
https://developer.android.com/reference/android/os/IBinder.html contextThread,
https://developer.android.com/reference/android/os/IBinder.html token,
https://developer.android.com/reference/java/lang/String.html target,
https://developer.android.com/reference/android/content/Intent.html intent,
int requestCode,
https://developer.android.com/reference/android/os/Bundle.html options
)`

This API was added in Android API 23 (M)
`https://developer.android.com/reference/android/app/Instrumentation.ActivityResult.html` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#execStartActivity(android.content.Context,android.os.IBinder,android.os.IBinder,android.app.Activity,android.content.Intent,int,android.os.Bundle,android.os.UserHandle)(
https://developer.android.com/reference/android/content/Context.html who,
https://developer.android.com/reference/android/os/IBinder.html contextThread,
https://developer.android.com/reference/android/os/IBinder.html token,
https://developer.android.com/reference/android/app/Activity.html target,
https://developer.android.com/reference/android/content/Intent.html intent,
int requestCode,
https://developer.android.com/reference/android/os/Bundle.html options,
https://developer.android.com/reference/android/os/UserHandle.html user
)`

This API was added in Android API 17 (JELLY_BEAN_MR1)
`void` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#finish(int,android.os.Bundle)(int resultCode, https://developer.android.com/reference/android/os/Bundle.html results)`

Ensures all activities launched in this instrumentation are finished before the instrumentation exits.
`https://developer.android.com/reference/java/lang/String.html` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#getThreadState()()` `void` `[installMultidex](https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#installMultidex())()`

**This method is deprecated.**

no-op: multidex is not necessary on SDKS \>= 23

<br />

`void` `[installOldMultiDex](https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#installOldMultiDex(java.lang.Class<?>))(https://developer.android.com/reference/java/lang/Class.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?> multidexClass)`

**This method is deprecated.**

no-op: multidex is not necessary on SDKS \>= 23

<br />

`void` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#interceptActivityUsing(androidx.test.runner.intercepting.InterceptingActivityFactory)(
https://developer.android.com/reference/androidx/test/runner/intercepting/InterceptingActivityFactory interceptingActivityFactory
)`

Use the given InterceptingActivityFactory to create Activity instance in `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#newActivity(java.lang.ClassLoader,java.lang.String,android.content.Intent)`.
`final boolean` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#isPrimaryInstrProcess()()`

Checks whether this instance of instrumentation should be considered as a primary instrumentation process.
`boolean` `[isPrimaryInstrProcess](https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#isPrimaryInstrProcess(java.lang.String))(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html argsProcessName)`

**This method is deprecated.**

use isPrimaryInstrProcess()

<br />

`https://developer.android.com/reference/android/app/Activity.html` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#newActivity(java.lang.ClassLoader,java.lang.String,android.content.Intent)(https://developer.android.com/reference/java/lang/ClassLoader.html cl, https://developer.android.com/reference/java/lang/String.html className, https://developer.android.com/reference/android/content/Intent.html intent)` `https://developer.android.com/reference/android/app/Activity.html` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#newActivity(java.lang.Class<?>,android.content.Context,android.os.IBinder,android.app.Application,android.content.Intent,android.content.pm.ActivityInfo,java.lang.CharSequence,android.app.Activity,java.lang.String,java.lang.Object)(
https://developer.android.com/reference/java/lang/Class.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?> clazz,
https://developer.android.com/reference/android/content/Context.html context,
https://developer.android.com/reference/android/os/IBinder.html token,
https://developer.android.com/reference/android/app/Application.html application,
https://developer.android.com/reference/android/content/Intent.html intent,
https://developer.android.com/reference/android/content/pm/ActivityInfo.html info,
https://developer.android.com/reference/java/lang/CharSequence.html title,
https://developer.android.com/reference/android/app/Activity.html parent,
https://developer.android.com/reference/java/lang/String.html id,
https://developer.android.com/reference/java/lang/Object.html lastNonConfigurationInstance
)` `https://developer.android.com/reference/android/app/Application.html` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#newApplication(java.lang.ClassLoader,java.lang.String,android.content.Context)(https://developer.android.com/reference/java/lang/ClassLoader.html cl, https://developer.android.com/reference/java/lang/String.html className, https://developer.android.com/reference/android/content/Context.html context)`

Does initialization before creating the application.
`void` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#onDestroy()()` `void` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#restoreUncaughtExceptionHandler()()` `void` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#runOnMainSync(java.lang.Runnable)(https://developer.android.com/reference/java/lang/Runnable.html runnable)`

Posts a runnable to the main thread and blocks the caller's thread until the runnable is executed.
`final void` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#setJsBridgeClassName(java.lang.String)(https://developer.android.com/reference/java/lang/String.html className)` `boolean` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#shouldWaitForActivitiesToComplete()()` `void` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#specifyDexMakerCacheProperty()()` `https://developer.android.com/reference/android/app/Activity.html` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#startActivitySync(android.content.Intent)(https://developer.android.com/reference/android/content/Intent.html intent)` `https://developer.android.com/reference/java/lang/Throwable.html` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#unwrapException(java.lang.Throwable)(https://developer.android.com/reference/java/lang/Throwable.html t)`

Unwraps an exception from certain wrapper types, e.g. RuntimeException.
`void` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#useDefaultInterceptingActivityFactory()()`

Use default mechanism of creating activity instance in `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#newActivity(java.lang.ClassLoader,java.lang.String,android.content.Intent)`
`void` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#waitForActivitiesToComplete()()`

Ensures we've onStopped() all activities which were onStarted().

## Public constructors

### AndroidJUnitRunner

```
public AndroidJUnitRunner()
```

## Public methods

### onCreate

```
public void onCreate(Bundle arguments)
```

Sets up lifecycle monitoring, and argument registry.

Subclasses must call up to onCreate(). This onCreate method does not call start() it is the subclasses responsibility to call start if it desires.

### onException

```
public boolean onException(Object obj, Throwable e)
```

### onStart

```
public void onStart()
```

This implementation of onStart() will guarantee that the Application's onCreate method has completed when it returns.

Subclasses should call super.onStart() before executing any code that touches the application and it's state.

### sendStatus

```
public void sendStatus(int resultCode, Bundle results)
```