# InstrumentationRegistry

Summary:[Methods](https://developer.android.com/reference/android/support/test/InstrumentationRegistry#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/test/InstrumentationRegistry#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/support/test/InstrumentationRegistry#)  

# InstrumentationRegistry

| This package is part of the Android[support library](https://developer.android.com/topic/libraries/support-library)which is no longer maintained. The support library has been superseded by[AndroidX](https://developer.android.com/jetpack/androidx)which is part of[Jetpack](https://developer.android.com/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider[migrating](https://developer.android.com/jetpack/androidx/migrate)existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library[class mappings](https://developer.android.com/jetpack/androidx/migrate/class-mappings).

`
public

final

class
InstrumentationRegistry
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object.html)`


``


`

|---|----------------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) ||
| ↳ | android.support.test.InstrumentationRegistry |

<br />

*** ** * ** ***

An exposed registry instance that holds a reference to the instrumentation running in the process and its arguments. Also provides an easy way for callers to get a hold of instrumentation, application context and instrumentation arguments Bundle.

## Summary

|                                                                                                                                                                                                                                                                                                      ### Public methods                                                                                                                                                                                                                                                                                                      ||
|-------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` static `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)                    | ` `[getArguments](https://developer.android.com/reference/android/support/test/InstrumentationRegistry#getArguments())`() ` Returns a copy of instrumentation arguments Bundle.                                                                                                                                                                                                                                                                                                                                       |
| ` static `[Context](https://developer.android.com/reference/android/content/Context.html)             | ` `[getContext](https://developer.android.com/reference/android/support/test/InstrumentationRegistry#getContext())`() ` Return the Context of this instrumentation's package.                                                                                                                                                                                                                                                                                                                                         |
| ` static `[Instrumentation](https://developer.android.com/reference/android/app/Instrumentation.html) | ` `[getInstrumentation](https://developer.android.com/reference/android/support/test/InstrumentationRegistry#getInstrumentation())`() ` Returns the instrumentation currently running.                                                                                                                                                                                                                                                                                                                                |
| ` static `[Context](https://developer.android.com/reference/android/content/Context.html)             | ` `[getTargetContext](https://developer.android.com/reference/android/support/test/InstrumentationRegistry#getTargetContext())`() ` Return a Context for the target application being instrumented.                                                                                                                                                                                                                                                                                                                   |
| ` static void`                                                                                        | ` `[registerInstance](https://developer.android.com/reference/android/support/test/InstrumentationRegistry#registerInstance(android.app.Instrumentation, android.os.Bundle))`(`[Instrumentation](https://developer.android.com/reference/android/app/Instrumentation.html)` instrumentation, `[Bundle](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. |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/test/InstrumentationRegistry#)From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object.html)` ` |-------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object.html)          | ` clone() `                                                                                | | ` boolean`                                                                          | ` equals(`[Object](https://developer.android.com/reference/java/lang/Object.html)` arg0) ` | | ` void`                                                                             | ` finalize() `                                                                             | | ` final `[Class](https://developer.android.com/reference/java/lang/Class.html)`<?>` | ` getClass() `                                                                             | | ` int`                                                                              | ` hashCode() `                                                                             | | ` final void`                                                                       | ` notify() `                                                                               | | ` final void`                                                                       | ` notifyAll() `                                                                            | | ` `[String](https://developer.android.com/reference/java/lang/String.html)          | ` toString() `                                                                             | | ` final void`                                                                       | ` wait(long arg0, int arg1) `                                                              | | ` final void`                                                                       | ` wait(long arg0) `                                                                        | | ` final void`                                                                       | ` wait() `                                                                                 | ||

## Public methods

### getArguments

```
Bundle getArguments ()
```

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

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

<br />

|                                                             Returns                                                             ||
|--------------------------------------------------------------------------|-------------------------------------------------------|
| [Bundle](https://developer.android.com/reference/android/os/Bundle.html) | Bundle the arguments for this instrumentation. <br /> |

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

### getContext

```
Context getContext ()
```

Return the Context of this instrumentation's package. Use this to get a[Context](https://developer.android.com/reference/android/content/Context.html)representing[getContext()](https://developer.android.com/reference/android/app/Instrumentation.html#getContext())into your test.

<br />

|                                         Returns                                         ||
|---------------------------------------------------------------------------------|--------|
| [Context](https://developer.android.com/reference/android/content/Context.html) | <br /> |

### getInstrumentation

```
Instrumentation getInstrumentation ()
```

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

<br />

|                                               Returns                                               ||
|---------------------------------------------------------------------------------------------|--------|
| [Instrumentation](https://developer.android.com/reference/android/app/Instrumentation.html) | <br /> |

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

### getTargetContext

```
Context getTargetContext ()
```

Return a Context for the target application being instrumented. Use this to get a[Context](https://developer.android.com/reference/android/content/Context.html)representing[getTargetContext()](https://developer.android.com/reference/android/app/Instrumentation.html#getTargetContext())into your test.

<br />

|                                         Returns                                         ||
|---------------------------------------------------------------------------------|--------|
| [Context](https://developer.android.com/reference/android/content/Context.html) | <br /> |

### registerInstance

```
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!

<br />

|                                                    Parameters                                                    ||
|-------------------|-----------------------------------------------------------------------------------------------|
| `instrumentation` | `Instrumentation`: the instrumentation currently running. <br />                              |
| `arguments`       | `Bundle`: the arguments for this application. Null deregisters any existing arguments. <br /> |

-

  ## Classes

  - [InstrumentationRegistry](https://developer.android.com/reference/android/support/test/InstrumentationRegistry)