# 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.java+class:androidx.work.testing.TestWorkerBuilder) Added in [2.1.0](https://developer.android.com/jetpack/androidx/releases/work#2.1.0)

*** ** * ** ***


```
class TestWorkerBuilder<W : Worker?> : TestListenableWorkerBuilder<W!>
```

<br />

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.work.testing.TestListenableWorkerBuilder](https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder)\<W!\> ||
|   | ↳ | [androidx.work.testing.TestWorkerBuilder](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.

| Parameters |
|---|---|
| `<W : https://developer.android.com/reference/kotlin/androidx/work/Worker?>` | The actual subtype of `https://developer.android.com/reference/kotlin/androidx/work/Worker` |

## Summary

| ### Public functions |
|---|---|
| `java-static https://developer.android.com/reference/kotlin/androidx/work/testing/TestWorkerBuilder<https://developer.android.com/reference/kotlin/androidx/work/Worker!>` | `https://developer.android.com/reference/kotlin/androidx/work/testing/TestWorkerBuilder#from(android.content.Context,androidx.work.WorkRequest,java.util.concurrent.Executor)(context: https://developer.android.com/reference/android/content/Context.html, workRequest: https://developer.android.com/reference/kotlin/androidx/work/WorkRequest, executor: https://developer.android.com/reference/java/util/concurrent/Executor.html)` Creates a new instance of a `https://developer.android.com/reference/kotlin/androidx/work/testing/TestWorkerBuilder` from a `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` that runs on the given `https://developer.android.com/reference/java/util/concurrent/Executor.html`. |
| `java-static 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/TestWorkerBuilder#from(android.content.Context,java.lang.Class<W>,java.util.concurrent.Executor)(context: https://developer.android.com/reference/android/content/Context.html, workerClass: https://developer.android.com/reference/java/lang/Class.html<W!>, executor: https://developer.android.com/reference/java/util/concurrent/Executor.html)` Creates a new instance of a `https://developer.android.com/reference/kotlin/androidx/work/testing/TestWorkerBuilder` with the worker `https://developer.android.com/reference/java/lang/Class.html` that runs on the given `https://developer.android.com/reference/java/util/concurrent/Executor.html`. |

### Inherited functions

From [androidx.work.testing.TestListenableWorkerBuilder](https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder) `W` `https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder#build()()`

Builds the `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker`.
`W` `https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder#build(java.lang.Class<? extends androidx.work.ListenableWorker>)(enqueuedClass: https://developer.android.com/reference/java/lang/Class.html<https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker!>)`

Builds the `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker` by passing in the enqueued `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker` class to the `https://developer.android.com/reference/kotlin/androidx/work/WorkerFactory`.
`java-static https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder<https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker!>` `https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder#from(android.content.Context,androidx.work.WorkRequest)(context: https://developer.android.com/reference/android/content/Context.html, workRequest: https://developer.android.com/reference/kotlin/androidx/work/WorkRequest)`

Creates a new instance of a `https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder` from a `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest`.
`java-static 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/TestListenableWorkerBuilder#from(android.content.Context,java.lang.Class<W>)(context: https://developer.android.com/reference/android/content/Context.html, workerClass: https://developer.android.com/reference/java/lang/Class.html<W!>)`

Creates a new instance of a `https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder` the worker `https://developer.android.com/reference/java/lang/Class.html`.
`https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder<W!>` `https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder#setForegroundUpdater(androidx.work.ForegroundUpdater)(updater: https://developer.android.com/reference/kotlin/androidx/work/ForegroundUpdater)`

Sets the `https://developer.android.com/reference/kotlin/androidx/work/ForegroundUpdater` to be used to construct the `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker`.
`https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder<W!>` `https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder#setId(java.util.UUID)(id: https://developer.android.com/reference/java/util/UUID.html)`

Sets the id for this unit of work.
`https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder<W!>` `https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder#setInputData(androidx.work.Data)(inputData: https://developer.android.com/reference/kotlin/androidx/work/Data)`

Adds input `https://developer.android.com/reference/kotlin/androidx/work/Data` to the work.
`https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder<W!>` `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 28)
https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder#setNetwork(android.net.Network)(network: https://developer.android.com/reference/android/net/Network.html)`

Sets the network associated with this unit of work.
`https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder<W!>` `https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder#setProgressUpdater(androidx.work.ProgressUpdater)(updater: https://developer.android.com/reference/kotlin/androidx/work/ProgressUpdater)`

Sets the `https://developer.android.com/reference/kotlin/androidx/work/ProgressUpdater` to be used to construct the `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker`.
`https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder<W!>` `https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder#setRunAttemptCount(int)(runAttemptCount: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`

Sets the initial run attempt count for this work.
`https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder<W!>` `https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder#setTags(java.util.List<java.lang.String>)(tags: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>)`

Sets the tags associated with this unit of work.
`https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder<W!>` `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 24)
https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder#setTriggeredContentAuthorities(java.util.List<java.lang.String>)(authorities: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>)`

Sets the authorities for content `https://developer.android.com/reference/android/net/Uri.html`'s associated with this unit of work.
`https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder<W!>` `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 24)
https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder#setTriggeredContentUris(java.util.List<android.net.Uri>)(contentUris: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/android/net/Uri.html!>)`

Sets the list of Content `https://developer.android.com/reference/android/net/Uri.html`s associated with this unit of work.
`https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder<W!>` `https://developer.android.com/reference/kotlin/androidx/work/testing/TestListenableWorkerBuilder#setWorkerFactory(androidx.work.WorkerFactory)(workerFactory: https://developer.android.com/reference/kotlin/androidx/work/WorkerFactory)`

Sets the `https://developer.android.com/reference/kotlin/androidx/work/WorkerFactory` to be used to construct the `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker`.

## Public functions

### from

Added in [2.1.0](https://developer.android.com/jetpack/androidx/releases/work#2.1.0)

```
java-static fun from(context: Context, workRequest: WorkRequest, executor: Executor): TestWorkerBuilder<Worker!>
```

Creates a new instance of a `https://developer.android.com/reference/kotlin/androidx/work/testing/TestWorkerBuilder` from a `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` that runs on the given `https://developer.android.com/reference/java/util/concurrent/Executor.html`.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | The `https://developer.android.com/reference/android/content/Context.html` |
| `workRequest: https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` | The `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` |
| `executor: https://developer.android.com/reference/java/util/concurrent/Executor.html` | The `https://developer.android.com/reference/java/util/concurrent/Executor.html` |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/work/testing/TestWorkerBuilder<https://developer.android.com/reference/kotlin/androidx/work/Worker!>` | The new instance of a `https://developer.android.com/reference/kotlin/androidx/work/testing/TestWorkerBuilder` |

### from

Added in [2.1.0](https://developer.android.com/jetpack/androidx/releases/work#2.1.0)

```
java-static fun <W : Worker?> from(context: Context, workerClass: Class<W!>, executor: Executor): TestWorkerBuilder<W!>
```

Creates a new instance of a `https://developer.android.com/reference/kotlin/androidx/work/testing/TestWorkerBuilder` with the worker `https://developer.android.com/reference/java/lang/Class.html` that runs on the given `https://developer.android.com/reference/java/util/concurrent/Executor.html`.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | The `https://developer.android.com/reference/android/content/Context.html` |
| `workerClass: https://developer.android.com/reference/java/lang/Class.html<W!>` | The subtype of `https://developer.android.com/reference/kotlin/androidx/work/Worker` being built |
| `executor: https://developer.android.com/reference/java/util/concurrent/Executor.html` | The `https://developer.android.com/reference/java/util/concurrent/Executor.html` |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/work/testing/TestWorkerBuilder<W!>` | The new instance of a `https://developer.android.com/reference/kotlin/androidx/work/testing/TestWorkerBuilder` |