# IdlingResource

Summary:[Nested Classes](https://developer.android.com/reference/android/support/test/espresso/IdlingResource#nestedclasses)\|[Methods](https://developer.android.com/reference/android/support/test/espresso/IdlingResource#pubmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/support/test/espresso/IdlingResource#)  

# IdlingResource

| This package is part of the Android[support library](https://developer.android.com/topic/libraries/support-library)which is no longer maintained. The support library has been superseded by[AndroidX](https://developer.android.com/jetpack/androidx)which is part of[Jetpack](https://developer.android.com/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider[migrating](https://developer.android.com/jetpack/androidx/migrate)existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library[class mappings](https://developer.android.com/jetpack/androidx/migrate/class-mappings).

`
public


interface
IdlingResource
`  
`


`

|----------------------------------------------|
| android.support.test.espresso.IdlingResource |

|---|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/test/espresso/IdlingResource#)Known Indirect Subclasses [CountingIdlingResource](https://developer.android.com/reference/android/support/test/espresso/idling/CountingIdlingResource),[IdlingScheduledThreadPoolExecutor](https://developer.android.com/reference/android/support/test/espresso/idling/concurrent/IdlingScheduledThreadPoolExecutor),[IdlingThreadPoolExecutor](https://developer.android.com/reference/android/support/test/espresso/idling/concurrent/IdlingThreadPoolExecutor),[UriIdlingResource](https://developer.android.com/reference/android/support/test/espresso/idling/net/UriIdlingResource) |----------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [CountingIdlingResource](https://developer.android.com/reference/android/support/test/espresso/idling/CountingIdlingResource)                                  | An implementation of[IdlingResource](https://developer.android.com/reference/android/support/test/espresso/IdlingResource)that determines idleness by maintaining an internal counter.                                                                                        | | [IdlingScheduledThreadPoolExecutor](https://developer.android.com/reference/android/support/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/android/support/test/espresso/IdlingResource)with Espresso. | | [IdlingThreadPoolExecutor](https://developer.android.com/reference/android/support/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/android/support/test/espresso/IdlingResource)with Espresso.                   | | [UriIdlingResource](https://developer.android.com/reference/android/support/test/espresso/idling/net/UriIdlingResource)                                        | An implementation of[IdlingResource](https://developer.android.com/reference/android/support/test/espresso/IdlingResource)useful for monitoring idleness of network traffic.                                                                                                  | ||

<br />

*** ** * ** ***

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

## Summary

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

|                                                                                                                                                                                                                                                                                                                 ### Public methods                                                                                                                                                                                                                                                                                                                 ||
|-------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` abstract `[String](https://developer.android.com/reference/java/lang/String.html) | ` `[getName](https://developer.android.com/reference/android/support/test/espresso/IdlingResource#getName())`() ` Returns the name of the resources (used for logging and idempotency of registration).                                                                                                                                                                                                                                                                                                                                                       |
| ` abstract boolean`                                                                 | ` `[isIdleNow](https://developer.android.com/reference/android/support/test/espresso/IdlingResource#isIdleNow())`() ` Returns`true`if resource is currently idle.                                                                                                                                                                                                                                                                                                                                                                                             |
| ` abstract void`                                                                    | ` `[registerIdleTransitionCallback](https://developer.android.com/reference/android/support/test/espresso/IdlingResource#registerIdleTransitionCallback(android.support.test.espresso.IdlingResource.ResourceCallback))`(`[IdlingResource.ResourceCallback](https://developer.android.com/reference/android/support/test/espresso/IdlingResource.ResourceCallback)` callback) ` Registers the given[IdlingResource.ResourceCallback](https://developer.android.com/reference/android/support/test/espresso/IdlingResource.ResourceCallback)with the resource. |

## Public methods

### getName

```
String getName ()
```

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

<br />

|                                     Returns                                     ||
|-------------------------------------------------------------------------|--------|
| [String](https://developer.android.com/reference/java/lang/String.html) | <br /> |

### isIdleNow

```
boolean isIdleNow ()
```

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.

<br />

|      Returns      ||
|-----------|--------|
| `boolean` | <br /> |

### registerIdleTransitionCallback

```
void registerIdleTransitionCallback (IdlingResource.ResourceCallback callback)
```

Registers the given[IdlingResource.ResourceCallback](https://developer.android.com/reference/android/support/test/espresso/IdlingResource.ResourceCallback)with the resource. Espresso will call this method:

- with its implementation of[IdlingResource.ResourceCallback](https://developer.android.com/reference/android/support/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.

<br />

|                      Parameters                      ||
|------------|------------------------------------------|
| `callback` | `IdlingResource.ResourceCallback` <br /> |

-

  ## Interfaces

  - [EspressoException](https://developer.android.com/reference/android/support/test/espresso/EspressoException)
  - [FailureHandler](https://developer.android.com/reference/android/support/test/espresso/FailureHandler)
  - [IdlingResource](https://developer.android.com/reference/android/support/test/espresso/IdlingResource)
  - [IdlingResource.ResourceCallback](https://developer.android.com/reference/android/support/test/espresso/IdlingResource.ResourceCallback)
  - [UiController](https://developer.android.com/reference/android/support/test/espresso/UiController)
  - [ViewAction](https://developer.android.com/reference/android/support/test/espresso/ViewAction)
  - [ViewAssertion](https://developer.android.com/reference/android/support/test/espresso/ViewAssertion)
  - [ViewFinder](https://developer.android.com/reference/android/support/test/espresso/ViewFinder)
  - [ViewInteractionComponent](https://developer.android.com/reference/android/support/test/espresso/ViewInteractionComponent)
-

  ## Classes

  - [AmbiguousViewMatcherException.Builder](https://developer.android.com/reference/android/support/test/espresso/AmbiguousViewMatcherException.Builder)
  - [DataInteraction](https://developer.android.com/reference/android/support/test/espresso/DataInteraction)
  - [DataInteraction.DisplayDataMatcher](https://developer.android.com/reference/android/support/test/espresso/DataInteraction.DisplayDataMatcher)
  - [Espresso](https://developer.android.com/reference/android/support/test/espresso/Espresso)
  - [IdlingPolicies](https://developer.android.com/reference/android/support/test/espresso/IdlingPolicies)
  - [IdlingPolicy](https://developer.android.com/reference/android/support/test/espresso/IdlingPolicy)
  - [IdlingRegistry](https://developer.android.com/reference/android/support/test/espresso/IdlingRegistry)
  - [NoMatchingViewException.Builder](https://developer.android.com/reference/android/support/test/espresso/NoMatchingViewException.Builder)
  - [PerformException.Builder](https://developer.android.com/reference/android/support/test/espresso/PerformException.Builder)
  - [Root](https://developer.android.com/reference/android/support/test/espresso/Root)
  - [Root.Builder](https://developer.android.com/reference/android/support/test/espresso/Root.Builder)
  - [ViewInteraction](https://developer.android.com/reference/android/support/test/espresso/ViewInteraction)
-

  ## Exceptions

  - [AmbiguousViewMatcherException](https://developer.android.com/reference/android/support/test/espresso/AmbiguousViewMatcherException)
  - [AppNotIdleException](https://developer.android.com/reference/android/support/test/espresso/AppNotIdleException)
  - [IdlingResourceTimeoutException](https://developer.android.com/reference/android/support/test/espresso/IdlingResourceTimeoutException)
  - [InjectEventSecurityException](https://developer.android.com/reference/android/support/test/espresso/InjectEventSecurityException)
  - [NoActivityResumedException](https://developer.android.com/reference/android/support/test/espresso/NoActivityResumedException)
  - [NoMatchingRootException](https://developer.android.com/reference/android/support/test/espresso/NoMatchingRootException)
  - [NoMatchingViewException](https://developer.android.com/reference/android/support/test/espresso/NoMatchingViewException)
  - [PerformException](https://developer.android.com/reference/android/support/test/espresso/PerformException)