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 constructors

Public functions

java-static Bundle!

This function is deprecated.

Use androidx.test.platform.app.InstrumentationRegistry#getArguments().

java-static Context!

This function is deprecated.

In most scenarios, androidx.test.core.app.ApplicationProvider#getApplicationContext() should be used instead of the instrumentation test context.

java-static Instrumentation!

This function is deprecated.

Use androidx.test.platform.app.InstrumentationRegistry#getInstrumentation().

java-static Context!

This function is deprecated.

Use androidx.test.core.app.ApplicationProvider#getApplicationContext().

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

This function is deprecated.

Use androidx.test.platform.app.InstrumentationRegistry#registerInstance(Instrumentation, Bundle).

Public constructors

InstrumentationRegistry

InstrumentationRegistry()

Public functions

getArguments

java-static fun getArguments(): 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: java.lang.IllegalStateException

If no argument bundle has been registered.

getContext

java-static fun getContext(): 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

java-static fun getInstrumentation(): 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: java.lang.IllegalStateException

If instrumentation hasn't been registered.

getTargetContext

java-static fun getTargetContext(): 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

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!

The instrumentation currently running.

arguments: Bundle!

The arguments for this application. Null deregisters any existing arguments.