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()")
getArguments()

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!
@InlineMe(replacement = "androidx.test.platform.app.InstrumentationRegistry.getInstrumentation()")
getInstrumentation()

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
@InlineMe(replacement = "androidx.test.platform.app.InstrumentationRegistry.registerInstance(instrumentation," + " arguments)")
registerInstance(instrumentation: Instrumentation!, arguments: Bundle!)

This function is deprecated.

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

Public functions

getArguments

@InlineMe(replacement = "androidx.test.platform.app.InstrumentationRegistry.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

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

@InlineMe(replacement = "androidx.test.platform.app.InstrumentationRegistry.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

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

@InlineMe(replacement = "androidx.test.platform.app.InstrumentationRegistry.registerInstance(instrumentation,"
              + " arguments)")
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.