InstrumentationRegistry
public final class InstrumentationRegistry
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 @NonNull Bundle |
This method is deprecated. use |
static @NonNull Context |
This method is deprecated. In most scenarios, should be used instead of the instrumentation test context. |
static @NonNull Instrumentation |
This method is deprecated. |
static @NonNull Context |
This method is deprecated. use getApplicationContext instead. |
static @NonNull void |
This method is deprecated. |
Public methods
getArguments
@NonNull
public static BundlegetArguments()
Returns a copy of instrumentation arguments Bundle. Use this to get a Bundle containing the command line arguments passed to Instrumentation into your test.
This Bundle is not guaranteed to be present under all instrumentations.
Returns | |
---|---|
Bundle |
Bundle the arguments for this instrumentation. |
Throws | |
---|---|
java.lang.IllegalStateException |
if no argument Bundle has been registered. |
getContext
@NonNull
public static ContextgetContext()
Return the Context of this instrumentation's package. Use this to get a Context representing Instrumentation#getContext() into your test.
getInstrumentation
@NonNull
public static InstrumentationgetInstrumentation()
Returns the instrumentation currently running. Use this to get an Instrumentation into your test.
Throws | |
---|---|
java.lang.IllegalStateException |
if instrumentation hasn't been registered |
getTargetContext
@NonNull
public static ContextgetTargetContext()
Return a Context for the target application being instrumented. Use this to get a Context representing Instrumentation#getTargetContext() into your test.
registerInstance
@NonNull
public static voidregisterInstance(
@NonNull Instrumentation instrumentation,
@NonNull 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!