Skip to content

Most visited

Recently visited

navigation

InstrumentationRegistry

public final class InstrumentationRegistry
extends Object

java.lang.Object
   ↳ android.support.test.InstrumentationRegistry


An exposed registry instance that holds a reference to the instrumentation running in the process and it's arguments. Also provides an easy way for callers to get a hold of instrumentation, application context and instrumentation arguments Bundle.

Summary

Public methods

static Bundle getArguments()

Returns a copy of instrumentation arguments Bundle.

static Context getContext()

Return the Context of this instrumentation's package.

static Instrumentation getInstrumentation()

Returns the instrumentation currently running.

static Context getTargetContext()

Return a Context for the target application being instrumented.

static void registerInstance(Instrumentation instrumentation, Bundle arguments)

Records/exposes the instrumentation currently running and stores a copy of the instrumentation arguments Bundle in the registry.

Inherited methods

From class java.lang.Object

Public methods

getArguments

Bundle getArguments ()

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
IllegalStateException if no argument Bundle has been registered.

getContext

Context getContext ()

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

Returns
Context

getInstrumentation

Instrumentation getInstrumentation ()

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

Returns
Instrumentation

Throws
IllegalStateException if instrumentation hasn't been registered

getTargetContext

Context getTargetContext ()

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

Returns
Context

registerInstance

void registerInstance (Instrumentation instrumentation, 
                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!

Parameters
instrumentation Instrumentation: the instrumentation currently running.

arguments Bundle: the arguments for this application. Null deregisters any existing arguments.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (Dec 2017 Android Platform & Tools Survey)