{% setvar book_path %}/reference/kotlin/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

InstrumentationRegistry

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 constructors

Public functions

java-static Bundle!

This function is deprecated.

use getArguments

java-static Context!

This function is deprecated.

In most scenarios, getApplicationContext should be used instead of the instrumentation test context.

java-static Instrumentation!

This function is deprecated.

use getInstrumentation

java-static Context!

This function is deprecated.

use getApplicationContext instead.

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

This function is deprecated.

use registerInstance

Public constructors

InstrumentationRegistry

InstrumentationRegistry()

Public functions

getArguments

java-static fun getArguments(): Bundle!

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: java.lang.IllegalStateException

if no argument Bundle has been registered.

getContext

java-static fun getContext(): Context!

Return the Context of this instrumentation's package. Use this to get a Context representing Instrumentation#getContext() into your test.

getInstrumentation

java-static fun getInstrumentation(): Instrumentation!

Returns the instrumentation currently running. Use this to get an Instrumentation into your test.

Throws
java.lang.IllegalStateException: java.lang.IllegalStateException

if instrumentation hasn't been registered

getTargetContext

java-static fun getTargetContext(): Context!

Return a Context for the target application being instrumented. Use this to get a Context representing Instrumentation#getTargetContext() into your test.

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.