# InstrumentationRegistry

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

*** ** * ** ***


```
public final class InstrumentationRegistry
```

<br />

*** ** * ** ***

> [!CAUTION]
> **This class is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/test/platform/app/InstrumentationRegistry` or `https://developer.android.com/reference/androidx/test/core/app/ApplicationProvider` instead.

An exposed registry instance that holds a reference to the instrumentation running in the process and the instrumentation arguments. Provides an easy way for callers to get access to the instrumentation, application context, and instrumentation arguments bundle.

## Summary

| ### Public methods |
|---|---|
| `static https://developer.android.com/reference/android/os/Bundle.html` | `@https://checkerframework.org/api/com/google/errorprone/annotations/InlineMe.html(replacement = "androidx.test.platform.app.InstrumentationRegistry.getArguments()") [getArguments](https://developer.android.com/reference/androidx/test/InstrumentationRegistry#getArguments())()` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/test/platform/app/InstrumentationRegistry#getArguments()`. <br /> |
| `static https://developer.android.com/reference/android/content/Context.html` | `[getContext](https://developer.android.com/reference/androidx/test/InstrumentationRegistry#getContext())()` **This method is deprecated.** In most scenarios, `https://developer.android.com/reference/androidx/test/core/app/ApplicationProvider#getApplicationContext()` should be used instead of the instrumentation test context. <br /> |
| `static https://developer.android.com/reference/android/app/Instrumentation.html` | `@https://checkerframework.org/api/com/google/errorprone/annotations/InlineMe.html(replacement = "androidx.test.platform.app.InstrumentationRegistry.getInstrumentation()") [getInstrumentation](https://developer.android.com/reference/androidx/test/InstrumentationRegistry#getInstrumentation())()` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/test/platform/app/InstrumentationRegistry#getInstrumentation()`. <br /> |
| `static https://developer.android.com/reference/android/content/Context.html` | `[getTargetContext](https://developer.android.com/reference/androidx/test/InstrumentationRegistry#getTargetContext())()` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/test/core/app/ApplicationProvider#getApplicationContext()`. <br /> |
| `static void` | `@https://checkerframework.org/api/com/google/errorprone/annotations/InlineMe.html(replacement = "androidx.test.platform.app.InstrumentationRegistry.registerInstance(instrumentation," + " arguments)") [registerInstance](https://developer.android.com/reference/androidx/test/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)` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/test/platform/app/InstrumentationRegistry#registerInstance(android.app.Instrumentation,android.os.Bundle)`. <br /> |

## Public methods

### getArguments

```
@InlineMe(replacement = "androidx.test.platform.app.InstrumentationRegistry.getArguments()")
public static Bundle [getArguments](https://developer.android.com/reference/androidx/test/InstrumentationRegistry#getArguments())()
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/test/platform/app/InstrumentationRegistry#getArguments()`.

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

The bundle is not guaranteed to be present under all instrumentations.

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

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

### getContext

```
public static Context [getContext](https://developer.android.com/reference/androidx/test/InstrumentationRegistry#getContext())()
```

> [!CAUTION]
> **This method is deprecated.**   
>
> In most scenarios, `https://developer.android.com/reference/androidx/test/core/app/ApplicationProvider#getApplicationContext()` should be used instead of the instrumentation test context. If you do need access to the test context to access its resources, use `https://developer.android.com/reference/android/content/pm/PackageManager#getResourcesForApplication(java.lang.String)` instead.

Returns the context of this instrumentation's package. Use this method to get a `https://developer.android.com/reference/android/content/Context` representing `https://developer.android.com/reference/android/app/Instrumentation#getContext()` into your test.

| Returns |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html` | The instrumentation context. |

### getInstrumentation

```
@InlineMe(replacement = "androidx.test.platform.app.InstrumentationRegistry.getInstrumentation()")
public static Instrumentation [getInstrumentation](https://developer.android.com/reference/androidx/test/InstrumentationRegistry#getInstrumentation())()
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/test/platform/app/InstrumentationRegistry#getInstrumentation()`.

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

| Returns |
|---|---|
| `https://developer.android.com/reference/android/app/Instrumentation.html` | The current instrumentation. |

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

### getTargetContext

```
public static Context [getTargetContext](https://developer.android.com/reference/androidx/test/InstrumentationRegistry#getTargetContext())()
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/test/core/app/ApplicationProvider#getApplicationContext()`.

Returns a context for the target application being instrumented. Use this method to get a `https://developer.android.com/reference/android/content/Context` representing `https://developer.android.com/reference/android/app/Instrumentation#getTargetContext()` into your test.

| Returns |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html` | The target application context. |

### registerInstance

```
@InlineMe(replacement = "androidx.test.platform.app.InstrumentationRegistry.registerInstance(instrumentation,"
              + " arguments)")
public static void [registerInstance](https://developer.android.com/reference/androidx/test/InstrumentationRegistry#registerInstance(android.app.Instrumentation,android.os.Bundle))(Instrumentation instrumentation, Bundle arguments)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/test/platform/app/InstrumentationRegistry#registerInstance(android.app.Instrumentation,android.os.Bundle)`.

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. |