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

IdlingResource

interface IdlingResource

Known direct subclasses
CountingIdlingResource

An implementation of IdlingResource that determines idleness by maintaining an internal counter.


Represents a resource of an application under test which can cause asynchronous background work to happen during test execution (e.g. an intent service that processes a button click). By default, Espresso synchronizes all view operations with the UI thread as well as AsyncTasks; however, it has no way of doing so with "hand-made" resources. In such cases, test authors can register the custom resource via androidx.test.espresso.IdlingRegistry and Espresso will wait for the resource to become idle prior to executing a view operation.

Important Note: it is assumed that the resource stays idle most of the time.

Note: before writing your implementation consider using instead.

Summary

Nested types

IdlingResource.ResourceCallback

Registered by an IdlingResource to notify Espresso of a transition to idle.

Public functions

String!

Returns the name of the resources (used for logging and idempotency of registration).

Boolean

Returns true if resource is currently idle.

Unit

Registers the given ResourceCallback with the resource.

Public functions

getName

fun getName(): String!

Returns the name of the resources (used for logging and idempotency of registration).

isIdleNow

fun isIdleNow(): Boolean

Returns true if resource is currently idle. Espresso will always call this method from the main thread, therefore it should be non-blocking and return immediately.

registerIdleTransitionCallback

fun registerIdleTransitionCallback(
    callback: IdlingResource.ResourceCallback!
): Unit

Registers the given ResourceCallback with the resource. Espresso will call this method:

You only need to call this upon transition from busy to idle - if the resource is already idle when the method is called invoking the call back is optional and has no significant impact.