# androidx.work.testing

*** ** * ** ***

Kotlin \|[Java](https://developer.android.com/reference/androidx/work/testing/package-summary "View this page in Java")

WorkManager Testing is a library for testing app code that runs using WorkManager.

This testing library provides a way to manually initialize WorkManager for tests by using `https://developer.android.com/reference/kotlin/androidx/work/testing/WorkManagerTestInitHelper`. Once initialized, you can use `https://developer.android.com/reference/kotlin/androidx/work/testing/WorkManagerTestInitHelper#getTestDriver(android.content.Context)` to drive constraints and timing-related triggers for your background work.

For ease of testing, this library defaults to using a synchronous `https://developer.android.com/reference/java/util/concurrent/Executor.html`; you can change this in the `https://developer.android.com/reference/kotlin/androidx/work/Configuration` if you wish.

## Interfaces

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/work/testing/TestDriver` | Additional functionality exposed for `https://developer.android.com/reference/kotlin/androidx/work/WorkManager` that are useful in the context of testing. |

## Classes

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/work/testing/SynchronousExecutor` | Is an implementation of a `https://developer.android.com/reference/java/util/concurrent/Executor.html` which executes `https://developer.android.com/reference/java/lang/Runnable.html`'s synchronously. |
| `https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder` | Builds instances of `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker` which can be used for testing. |
| `https://developer.android.com/reference/kotlin/androidx/work/testing/TestWorkerBuilder` | Builds instances of `https://developer.android.com/reference/kotlin/androidx/work/Worker` which can be used for testing. |
| `https://developer.android.com/reference/kotlin/androidx/work/testing/WorkManagerTestInitHelper` | Helps initialize `https://developer.android.com/reference/kotlin/androidx/work/WorkManager` for testing. |

## Enums

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/work/testing/WorkManagerTestInitHelper.ExecutorsMode` | Modes that control which executors are used in tests. |

## Top-level functions summary

|---|---|
| `inline https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder<W>` | `<W : https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker> https://developer.android.com/reference/kotlin/androidx/work/testing/package-summary#TestListenableWorkerBuilder(android.content.Context,androidx.work.Data,kotlin.collections.List,kotlin.Int,kotlin.collections.List,kotlin.collections.List)( context: https://developer.android.com/reference/android/content/Context.html, inputData: https://developer.android.com/reference/kotlin/androidx/work/Data, tags: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>, runAttemptCount: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, triggeredContentUris: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/android/net/Uri.html>, triggeredContentAuthorities: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html> )` Builds an instance of `https://developer.android.com/reference/kotlin/androidx/work/testing/package-summary#TestListenableWorkerBuilder(android.content.Context,androidx.work.Data,kotlin.collections.List,kotlin.Int,kotlin.collections.List,kotlin.collections.List)`. |
| `inline https://developer.android.com/reference/kotlin/androidx/work/testing/TestWorkerBuilder<W>` | `<W : https://developer.android.com/reference/kotlin/androidx/work/Worker> https://developer.android.com/reference/kotlin/androidx/work/testing/package-summary#TestWorkerBuilder(android.content.Context,java.util.concurrent.Executor,androidx.work.Data,kotlin.collections.List,kotlin.Int,kotlin.collections.List,kotlin.collections.List)( context: https://developer.android.com/reference/android/content/Context.html, executor: https://developer.android.com/reference/java/util/concurrent/Executor.html, inputData: https://developer.android.com/reference/kotlin/androidx/work/Data, tags: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>, runAttemptCount: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, triggeredContentUris: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/android/net/Uri.html>, triggeredContentAuthorities: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html> )` Builds an instance of `https://developer.android.com/reference/kotlin/androidx/work/testing/package-summary#TestWorkerBuilder(android.content.Context,java.util.concurrent.Executor,androidx.work.Data,kotlin.collections.List,kotlin.Int,kotlin.collections.List,kotlin.collections.List)`. |

## Top-level functions

### TestListenableWorkerBuilder

Artifact: [androidx.work:work-testing](https://developer.android.com/jetpack/androidx/releases/work) [View Source](https://cs.android.com/search?q=file:androidx/work/testing/TestListenableWorkerBuilder.kt+function:TestListenableWorkerBuilder)

```
inline fun <W : ListenableWorker> TestListenableWorkerBuilder(
    context: Context,
    inputData: Data = Data.EMPTY,
    tags: List<String> = emptyList(),
    runAttemptCount: Int = 1,
    triggeredContentUris: List<Uri> = emptyList(),
    triggeredContentAuthorities: List<String> = emptyList()
): TestListenableWorkerBuilder<W>
```

Builds an instance of `https://developer.android.com/reference/kotlin/androidx/work/testing/package-summary#TestListenableWorkerBuilder(android.content.Context,androidx.work.Data,kotlin.collections.List,kotlin.Int,kotlin.collections.List,kotlin.collections.List)`.

| Parameters |
|---|---|
| `<W : https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker>` | The subtype of `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker` |
| `context: https://developer.android.com/reference/android/content/Context.html` | The application `https://developer.android.com/reference/android/content/Context.html` |
| `inputData: https://developer.android.com/reference/kotlin/androidx/work/Data = Data.EMPTY` | The input data for the `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker` |
| `tags: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html> = emptyList()` | The tags associated with this `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker` |
| `runAttemptCount: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 1` | The run attempt count of the `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker` |
| `triggeredContentUris: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/android/net/Uri.html> = emptyList()` | The list of triggered content `https://developer.android.com/reference/android/net/Uri.html`s |
| `triggeredContentAuthorities: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html> = emptyList()` | The list of triggered content authorities |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder<W>` | The instance of `https://developer.android.com/reference/kotlin/androidx/work/testing/package-summary#TestListenableWorkerBuilder(android.content.Context,androidx.work.Data,kotlin.collections.List,kotlin.Int,kotlin.collections.List,kotlin.collections.List)` |

### TestWorkerBuilder

Artifact: [androidx.work:work-testing](https://developer.android.com/jetpack/androidx/releases/work) [View Source](https://cs.android.com/search?q=file:androidx/work/testing/TestWorkerBuilder.kt+function:TestWorkerBuilder)

```
inline fun <W : Worker> TestWorkerBuilder(
    context: Context,
    executor: Executor,
    inputData: Data = Data.EMPTY,
    tags: List<String> = emptyList(),
    runAttemptCount: Int = 1,
    triggeredContentUris: List<Uri> = emptyList(),
    triggeredContentAuthorities: List<String> = emptyList()
): TestWorkerBuilder<W>
```

Builds an instance of `https://developer.android.com/reference/kotlin/androidx/work/testing/package-summary#TestWorkerBuilder(android.content.Context,java.util.concurrent.Executor,androidx.work.Data,kotlin.collections.List,kotlin.Int,kotlin.collections.List,kotlin.collections.List)`.

| Parameters |
|---|---|
| `<W : https://developer.android.com/reference/kotlin/androidx/work/Worker>` | The subtype of `https://developer.android.com/reference/kotlin/androidx/work/Worker` |
| `context: https://developer.android.com/reference/android/content/Context.html` | The application `https://developer.android.com/reference/android/content/Context.html` |
| `executor: https://developer.android.com/reference/java/util/concurrent/Executor.html` | The `https://developer.android.com/reference/java/util/concurrent/Executor.html` that the `https://developer.android.com/reference/kotlin/androidx/work/Worker` runs on |
| `inputData: https://developer.android.com/reference/kotlin/androidx/work/Data = Data.EMPTY` | The input data for the `https://developer.android.com/reference/kotlin/androidx/work/Worker` |
| `tags: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html> = emptyList()` | The tags associated with this `https://developer.android.com/reference/kotlin/androidx/work/Worker` |
| `runAttemptCount: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 1` | The run attempt count of the `https://developer.android.com/reference/kotlin/androidx/work/Worker` |
| `triggeredContentUris: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/android/net/Uri.html> = emptyList()` | The list of triggered content `https://developer.android.com/reference/android/net/Uri.html`s |
| `triggeredContentAuthorities: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html> = emptyList()` | The list of triggered content authorities |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/work/testing/TestWorkerBuilder<W>` | The instance of `https://developer.android.com/reference/kotlin/androidx/work/testing/package-summary#TestWorkerBuilder(android.content.Context,java.util.concurrent.Executor,androidx.work.Data,kotlin.collections.List,kotlin.Int,kotlin.collections.List,kotlin.collections.List)` |