# IdlingResource

# IdlingResource

Artifact:[androidx.test.espresso:espresso-idling-resource](https://developer.android.com/jetpack/androidx/releases/test-espresso)  
[View Source](https://cs.android.com/search?q=file:androidx/test/espresso/IdlingResource.java+class:androidx.test.espresso.IdlingResource)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/test/espresso/IdlingResource "View this page in Java")

<br />

```
interface IdlingResource
```

<br />

Known direct subclasses  
[CountingIdlingResource](https://developer.android.com/reference/kotlin/androidx/test/espresso/idling/CountingIdlingResource),[IdlingScheduledThreadPoolExecutor](https://developer.android.com/reference/kotlin/androidx/test/espresso/idling/concurrent/IdlingScheduledThreadPoolExecutor),[IdlingThreadPoolExecutor](https://developer.android.com/reference/kotlin/androidx/test/espresso/idling/concurrent/IdlingThreadPoolExecutor),[UriIdlingResource](https://developer.android.com/reference/kotlin/androidx/test/espresso/idling/net/UriIdlingResource)  

|----------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [CountingIdlingResource](https://developer.android.com/reference/kotlin/androidx/test/espresso/idling/CountingIdlingResource)                                  | An implementation of[IdlingResource](https://developer.android.com/reference/kotlin/androidx/test/espresso/IdlingResource)that determines idleness by maintaining an internal counter.                                                                                        |
| [IdlingScheduledThreadPoolExecutor](https://developer.android.com/reference/kotlin/androidx/test/espresso/idling/concurrent/IdlingScheduledThreadPoolExecutor) | A[ScheduledThreadPoolExecutor](https://developer.android.com/reference/java/util/concurrent/ScheduledThreadPoolExecutor.html)that can be registered as an[IdlingResource](https://developer.android.com/reference/kotlin/androidx/test/espresso/IdlingResource)with Espresso. |
| [IdlingThreadPoolExecutor](https://developer.android.com/reference/kotlin/androidx/test/espresso/idling/concurrent/IdlingThreadPoolExecutor)                   | A[ThreadPoolExecutor](https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html)that can be registered as an[IdlingResource](https://developer.android.com/reference/kotlin/androidx/test/espresso/IdlingResource)with Espresso.                   |
| [UriIdlingResource](https://developer.android.com/reference/kotlin/androidx/test/espresso/idling/net/UriIdlingResource)                                        | An implementation of[IdlingResource](https://developer.android.com/reference/kotlin/androidx/test/espresso/IdlingResource)useful for monitoring idleness of network traffic.                                                                                                  |

*** ** * ** ***

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](https://developer.android.com/reference/kotlin/androidx/test/espresso/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](https://developer.android.com/reference/kotlin/androidx/test/espresso/IdlingRegistry)and[Espresso](https://developer.android.com/reference/kotlin/androidx/test/espresso/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[androidx.test.espresso.idling.CountingIdlingResource](https://developer.android.com/reference/kotlin/androidx/test/espresso/idling/CountingIdlingResource)instead.

## Summary

|                                                                                                                                                    ### Nested types                                                                                                                                                    |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `interface `[IdlingResource.ResourceCallback](https://developer.android.com/reference/kotlin/androidx/test/espresso/IdlingResource.ResourceCallback) Registered by an[IdlingResource](https://developer.android.com/reference/kotlin/androidx/test/espresso/IdlingResource)to notify Espresso of a transition to idle. |

|                                 ### Public functions                                 |
|--------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!` | [getName](https://developer.android.com/reference/kotlin/androidx/test/espresso/IdlingResource#getName())`()` Returns the name of the resources (used for logging and idempotency of registration).                                                                                                                                                                                                                                                                                                                                          |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)  | [isIdleNow](https://developer.android.com/reference/kotlin/androidx/test/espresso/IdlingResource#isIdleNow())`()` Returns`true`if resource is currently idle.                                                                                                                                                                                                                                                                                                                                                                                |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)        | [registerIdleTransitionCallback](https://developer.android.com/reference/kotlin/androidx/test/espresso/IdlingResource#registerIdleTransitionCallback(androidx.test.espresso.IdlingResource.ResourceCallback))`(` ` callback: `[IdlingResource.ResourceCallback](https://developer.android.com/reference/kotlin/androidx/test/espresso/IdlingResource.ResourceCallback)`!` `)` Registers the given[ResourceCallback](https://developer.android.com/reference/kotlin/androidx/test/espresso/IdlingResource.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](https://developer.android.com/reference/kotlin/androidx/test/espresso/IdlingResource.ResourceCallback)with the resource. Espresso will call this method:

- with its implementation of[ResourceCallback](https://developer.android.com/reference/kotlin/androidx/test/espresso/IdlingResource.ResourceCallback)so it can be notified asynchronously that your resource is idle
- from the main thread, but you are free to execute the callback's onTransitionToIdle from any thread
- once (when it is initially given a reference to your IdlingResource)

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.