InstrumentationRegistry
public final class InstrumentationRegistry
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 Bundle |
@InlineMe(replacement = "androidx.test.platform.app.InstrumentationRegistry.getArguments()")This method is deprecated. Use |
static Context |
This method is deprecated. In most scenarios, |
static Instrumentation |
@InlineMe(replacement = "androidx.test.platform.app.InstrumentationRegistry.getInstrumentation()")This method is deprecated. Use |
static Context |
This method is deprecated. Use |
static void |
@InlineMe(replacement = "androidx.test.platform.app.InstrumentationRegistry.registerInstance(instrumentation,"
+ " arguments)")This method is deprecated. Use |
Public methods
getArguments
@InlineMe(replacement = "androidx.test.platform.app.InstrumentationRegistry.getArguments()")
public static BundlegetArguments()
Returns a copy of the instrumentation arguments bundle. Use this method to get a Bundle containing the command-line arguments passed to Instrumentation into your test.
The bundle is not guaranteed to be present under all instrumentations.
| Returns | |
|---|---|
Bundle |
The arguments bundle for this instrumentation. |
| Throws | |
|---|---|
java.lang.IllegalStateException |
If no argument bundle has been registered. |
getContext
public static ContextgetContext()
Returns the context of this instrumentation's package. Use this method to get a Context representing Instrumentation#getContext() into your test.
| Returns | |
|---|---|
Context |
The instrumentation context. |
getInstrumentation
@InlineMe(replacement = "androidx.test.platform.app.InstrumentationRegistry.getInstrumentation()")
public static InstrumentationgetInstrumentation()
Returns the instrumentation currently running. Use this method to get an Instrumentation into your test.
| Returns | |
|---|---|
Instrumentation |
The current instrumentation. |
| Throws | |
|---|---|
java.lang.IllegalStateException |
If instrumentation hasn't been registered. |
getTargetContext
public static ContextgetTargetContext()
Returns a context for the target application being instrumented. Use this method to get a Context representing
Instrumentation#getTargetContext() into your test.
| Returns | |
|---|---|
Context |
The target application context. |
registerInstance
@InlineMe(replacement = "androidx.test.platform.app.InstrumentationRegistry.registerInstance(instrumentation," + " arguments)")
public static voidregisterInstance(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 | |
|---|---|
Instrumentation instrumentation |
The instrumentation currently running. |
Bundle arguments |
The arguments for this application. Null deregisters any existing arguments. |