Mobile Testing
IdlingResource
Also known as: Espresso IdlingResource, idling resource
An IdlingResource is an Espresso interface that tells the test runner when a background operation has finished, extending Espresso’s automatic synchronisation to work the main thread cannot see.
Espresso’s central design is that it waits for the main thread to become idle before performing the next action, which removes the need for sleeps in most tests. The waiting is only as good as its visibility, though: it accounts for the message queue, view hierarchy and AsyncTask, but not for a thread pool, an OkHttp dispatcher, a coroutine on a custom dispatcher, or a long-running animation. Work in those places is invisible, so Espresso proceeds while the app is still busy.
An IdlingResource closes that gap by reporting a busy/idle state Espresso polls. The practical alternative — inserting a fixed sleep — is what makes a test both slow and flaky, since the duration must be long enough for the worst machine and is still wrong on a bad day. Registering an idling resource, or injecting a test dispatcher so the work becomes synchronous, are the two durable fixes.
- Espresso waits for main-thread idleness; work off that thread is invisible to it.
- The failure mode is a test that passes locally and flakes on a loaded CI runner.
- Prefer an IdlingResource or a test dispatcher over a fixed sleep.
Learn more
Related terms
See it in your own test results
Qualflare detects flaky tests, clusters failures by root cause, and scores release risk from the test results you already produce in CI. Start free.
Start free with Qualflare← Back to the testing & observability glossary.
Last reviewed September 10, 2026