IdlingRegistry

public final class IdlingRegistry
extends Object

java.lang.Object
   ↳ androidx.test.espresso.IdlingRegistry


Handles registering and unregistering of IdlingResources with Espresso from within your application code.

These resources are required by Espresso to provide synchronisation against your application code. All registered resources with this registry will be automatically synchronized against for each Espresso interaction.

This registry along with IdlingResource interface are bundled together in a small light weight module so that it can be pulled in as a dependency of the App under test with close to no overhead.

Summary

Public methods

static IdlingRegistry getInstance()

Returns a singleton instance of this IdlingRegistry that should be globally used for registering and unregistering IdlingResources

Collection<Looper> getLoopers()
Collection<IdlingResource> getResources()

Returns a set of all currently registered IdlingResources.

boolean register(IdlingResource... idlingResources)

Registers one or more IdlingResources.

void registerLooperAsIdlingResource(Looper looper)

Registers a Looper for idle checking with the framework.

boolean unregister(IdlingResource... idlingResources)

Unregisters one or more IdlingResources.

boolean unregisterLooperAsIdlingResource(Looper looper)

Unregisters a Looper.

Inherited methods

Public methods

getInstance

public static IdlingRegistry getInstance ()

Returns a singleton instance of this IdlingRegistry that should be globally used for registering and unregistering IdlingResources

Returns
IdlingRegistry

getLoopers

public Collection<Looper> getLoopers ()

Returns
Collection<Looper> a set of all currently registered Loopers.

getResources

public Collection<IdlingResource> getResources ()

Returns a set of all currently registered IdlingResources.

Returns
Collection<IdlingResource>

register

public boolean register (IdlingResource... idlingResources)

Registers one or more IdlingResources. When registering more than one resource, ensure that each has a unique name returned from IdlingResource.getName()

Parameters
idlingResources IdlingResource

Returns
boolean true if at least one resource was successfully added to the registry

registerLooperAsIdlingResource

public void registerLooperAsIdlingResource (Looper looper)

Registers a Looper for idle checking with the framework. This is intended for use with non-UI thread Loopers only.

Parameters
looper Looper

Throws
IllegalArgumentException if looper is the main looper.
NullPointerException if looper is null.

unregister

public boolean unregister (IdlingResource... idlingResources)

Unregisters one or more IdlingResources.

Parameters
idlingResources IdlingResource

Returns
boolean true if at least one resource was successfully removed from the registry

unregisterLooperAsIdlingResource

public boolean unregisterLooperAsIdlingResource (Looper looper)

Unregisters a Looper.

Attempting to unregister a looper that is not registered is a no-op.

Parameters
looper Looper

Returns
boolean true if the looper was successfully removed from the registry