# InstrumentationRegistry

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

*** ** * ** ***


```
public final class InstrumentationRegistry
```

<br />

*** ** * ** ***

An exposed registry instance that holds a reference to the instrumentation running in the process and its arguments.

Instrumentation and InstrumentationRegistry are low level APIs, typically used by higher level test frameworks. It is generally not recommended for direct use by most tests.

## Summary

| ### Public methods |
|---|---|
| `static https://developer.android.com/reference/android/os/Bundle.html` | `https://developer.android.com/reference/androidx/test/platform/app/InstrumentationRegistry#getArguments()()` Returns a copy of instrumentation arguments Bundle. |
| `static https://developer.android.com/reference/android/app/Instrumentation.html` | `https://developer.android.com/reference/androidx/test/platform/app/InstrumentationRegistry#getInstrumentation()()` Returns the instrumentation currently running. |
| `static void` | `https://developer.android.com/reference/androidx/test/platform/app/InstrumentationRegistry#registerInstance(android.app.Instrumentation,android.os.Bundle)(https://developer.android.com/reference/android/app/Instrumentation.html instrumentation, https://developer.android.com/reference/android/os/Bundle.html arguments)` Records/exposes the instrumentation currently running and stores a copy of the instrumentation arguments Bundle in the registry. |

## Public methods

### getArguments

```
public static Bundle getArguments()
```

Returns a copy of instrumentation arguments Bundle. Use this to get a `https://developer.android.com/reference/android/os/Bundle.html` containing the command line arguments passed to `https://developer.android.com/reference/android/app/Instrumentation.html` into your test.

This Bundle is not guaranteed to be present under all instrumentations.

| Returns |
|---|---|
| `https://developer.android.com/reference/android/os/Bundle.html` | Bundle the arguments for this instrumentation. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if no argument Bundle has been registered. |

### getInstrumentation

```
public static Instrumentation getInstrumentation()
```

Returns the instrumentation currently running. Use this to get an `https://developer.android.com/reference/android/app/Instrumentation.html` into your test.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if instrumentation hasn't been registered |

### registerInstance

```
public static void registerInstance(Instrumentation instrumentation, Bundle arguments)
```

Records/exposes the instrumentation currently running and stores a copy of the instrumentation arguments Bundle in the registry.

This is a global registry - so be aware of the impact of calling this method!

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/app/Instrumentation.html instrumentation` | the instrumentation currently running. |
| `https://developer.android.com/reference/android/os/Bundle.html arguments` | the arguments for this application. Null deregisters any existing arguments. |