InstrumentationRegistry
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 functions |
|
|---|---|
java-static Bundle! |
@InlineMe(replacement = "androidx.test.platform.app.InstrumentationRegistry.getArguments()")This function is deprecated. Use |
java-static Context! |
This function is deprecated. In most scenarios, |
java-static Instrumentation! |
@InlineMe(replacement = "androidx.test.platform.app.InstrumentationRegistry.getInstrumentation()")This function is deprecated. Use |
java-static Context! |
This function is deprecated. Use |
java-static Unit |
@InlineMe(replacement = "androidx.test.platform.app.InstrumentationRegistry.registerInstance(instrumentation,"
+ " arguments)")This function is deprecated. Use |
Public functions
getArguments
@InlineMe(replacement = "androidx.test.platform.app.InstrumentationRegistry.getArguments()")
java-static fungetArguments(): Bundle!
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
java-static fungetContext(): Context!
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()")
java-static fungetInstrumentation(): Instrumentation!
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
java-static fungetTargetContext(): Context!
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)")
java-static funregisterInstance(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! |
The instrumentation currently running. |
arguments: Bundle! |
The arguments for this application. Null deregisters any existing arguments. |