# InstrumentationRegistry

# 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)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/test/platform/app/InstrumentationRegistry "View this page in Java")

<br />

```
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 functions                                             |
|--------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)`!`                    | [getArguments](https://developer.android.com/reference/kotlin/androidx/test/platform/app/InstrumentationRegistry#getArguments())`()` Returns a copy of instrumentation arguments Bundle.                                                                                                                                                                                                                                                                                                                                          |
| `java-static `[Instrumentation](https://developer.android.com/reference/android/app/Instrumentation.html)`!` | [getInstrumentation](https://developer.android.com/reference/kotlin/androidx/test/platform/app/InstrumentationRegistry#getInstrumentation())`()` Returns the instrumentation currently running.                                                                                                                                                                                                                                                                                                                                   |
| `java-static `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                  | [registerInstance](https://developer.android.com/reference/kotlin/androidx/test/platform/app/InstrumentationRegistry#registerInstance(android.app.Instrumentation,android.os.Bundle))`(instrumentation: `[Instrumentation](https://developer.android.com/reference/android/app/Instrumentation.html)`!, arguments: `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)`!)` Records/exposes the instrumentation currently running and stores a copy of the instrumentation arguments Bundle in the registry. |

## Public functions

### getArguments

```
java-static fun getArguments(): Bundle!
```

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.  

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

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

### getInstrumentation

```
java-static fun getInstrumentation(): Instrumentation!
```

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

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

### registerInstance

```
java-static fun registerInstance(instrumentation: Instrumentation!, arguments: Bundle!): Unit
```

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                                                     |
|-------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------|
| `instrumentation: `[Instrumentation](https://developer.android.com/reference/android/app/Instrumentation.html)`!` | the instrumentation currently running.                                       |
| `arguments: `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)`!`                          | the arguments for this application. Null deregisters any existing arguments. |