Android 12 Developer Preview is here! Try it out, and give us your feedback!

IdlingResource

interface IdlingResource
androidx.compose.ui.test.IdlingResource

Represents a resource of an application under test which can cause asynchronous background work to happen during test execution (e.g. an http request in response to a button click).

By default, all interactions from the test with the compose tree (finding nodes, performing gestures, making assertions) will be synchronized with pending work in Compose's internals (such as applying state changes, recomposing, measuring, etc). This ensures that the UI is in a stable state when the interactions are performed, so that e.g. no pending recompositions are still scheduled that could potentially change the UI. However, any asynchronous work that is not done through one of Compose's mechanisms won't be included in the default synchronization. For such work, test authors can create an IdlingResource and register it into the test with registerIdlingResource, and the interaction will wait for that resource to become idle prior to performing it.

Summary

Public methods
open String?

Returns diagnostics that explain why the idling resource is busy, or null if the resource is not busy.

Properties
abstract Boolean

Whether or not the IdlingResource is idle when reading this value.

Public methods

getDiagnosticMessageIfBusy

open fun getDiagnosticMessageIfBusy(): String?

Returns diagnostics that explain why the idling resource is busy, or null if the resource is not busy. Default implementation returns null.

Properties

isIdleNow

abstract val isIdleNow: Boolean

Whether or not the IdlingResource is idle when reading this value. This should always be called from the main thread, which is why it should be lightweight and fast.

If one idling resource returns false, the synchronization system will keep polling all idling resources until they are all idle.