# 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)

*** ** * ** ***


```
public class TestWorkerBuilder<W extends Worker> extends TestListenableWorkerBuilder<W>
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.work.testing.TestListenableWorkerBuilder](https://developer.android.com/reference/androidx/work/testing/TestListenableWorkerBuilder)\<W\> ||
|   | ↳ | [androidx.work.testing.TestWorkerBuilder](https://developer.android.com/reference/androidx/work/testing/TestWorkerBuilder) |

*** ** * ** ***

Builds instances of `https://developer.android.com/reference/androidx/work/Worker` which can be used for testing.

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

## Summary

| ### Public methods |
|---|---|
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/testing/TestWorkerBuilder<https://developer.android.com/reference/androidx/work/Worker>` | `https://developer.android.com/reference/androidx/work/testing/TestWorkerBuilder#from(android.content.Context,androidx.work.WorkRequest,java.util.concurrent.Executor)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/WorkRequest workRequest, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/concurrent/Executor.html executor )` Creates a new instance of a `https://developer.android.com/reference/androidx/work/testing/TestWorkerBuilder` from a `https://developer.android.com/reference/androidx/work/WorkRequest` that runs on the given `https://developer.android.com/reference/java/util/concurrent/Executor.html`. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/testing/TestWorkerBuilder<W>` | `<W extends https://developer.android.com/reference/androidx/work/Worker> https://developer.android.com/reference/androidx/work/testing/TestWorkerBuilder#from(android.content.Context,java.lang.Class<W>,java.util.concurrent.Executor)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<W> workerClass, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/concurrent/Executor.html executor )` Creates a new instance of a `https://developer.android.com/reference/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 methods

From [androidx.work.testing.TestListenableWorkerBuilder](https://developer.android.com/reference/androidx/work/testing/TestListenableWorkerBuilder) `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html W` `https://developer.android.com/reference/androidx/work/testing/TestListenableWorkerBuilder#build()()`

Builds the `https://developer.android.com/reference/androidx/work/ListenableWorker`.
`@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html W` `https://developer.android.com/reference/androidx/work/testing/TestListenableWorkerBuilder#build(java.lang.Class<? extends androidx.work.ListenableWorker>)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<https://developer.android.com/reference/androidx/work/ListenableWorker> enqueuedClass)`

Builds the `https://developer.android.com/reference/androidx/work/ListenableWorker` by passing in the enqueued `https://developer.android.com/reference/androidx/work/ListenableWorker` class to the `https://developer.android.com/reference/androidx/work/WorkerFactory`.
`static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/testing/TestListenableWorkerBuilder<https://developer.android.com/reference/androidx/work/ListenableWorker>` `https://developer.android.com/reference/androidx/work/testing/TestListenableWorkerBuilder#from(android.content.Context,androidx.work.WorkRequest)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/WorkRequest workRequest)`

Creates a new instance of a `https://developer.android.com/reference/androidx/work/testing/TestListenableWorkerBuilder` from a `https://developer.android.com/reference/androidx/work/WorkRequest`.
`static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/testing/TestListenableWorkerBuilder<W>` `<W extends https://developer.android.com/reference/androidx/work/ListenableWorker> https://developer.android.com/reference/androidx/work/testing/TestListenableWorkerBuilder#from(android.content.Context,java.lang.Class<W>)(
@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context,
@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<W> workerClass
)`

Creates a new instance of a `https://developer.android.com/reference/androidx/work/testing/TestListenableWorkerBuilder` the worker `https://developer.android.com/reference/java/lang/Class.html`.
`@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/testing/TestListenableWorkerBuilder<W>` `https://developer.android.com/reference/androidx/work/testing/TestListenableWorkerBuilder#setForegroundUpdater(androidx.work.ForegroundUpdater)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/ForegroundUpdater updater)`

Sets the `https://developer.android.com/reference/androidx/work/ForegroundUpdater` to be used to construct the `https://developer.android.com/reference/androidx/work/ListenableWorker`.
`@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/testing/TestListenableWorkerBuilder<W>` `https://developer.android.com/reference/androidx/work/testing/TestListenableWorkerBuilder#setId(java.util.UUID)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/UUID.html id)`

Sets the id for this unit of work.
`@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/testing/TestListenableWorkerBuilder<W>` `https://developer.android.com/reference/androidx/work/testing/TestListenableWorkerBuilder#setInputData(androidx.work.Data)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/Data inputData)`

Adds input `https://developer.android.com/reference/androidx/work/Data` to the work.
`@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/testing/TestListenableWorkerBuilder<W>` `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 28)
https://developer.android.com/reference/androidx/work/testing/TestListenableWorkerBuilder#setNetwork(android.net.Network)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Network.html network)`

Sets the network associated with this unit of work.
`@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/testing/TestListenableWorkerBuilder<W>` `https://developer.android.com/reference/androidx/work/testing/TestListenableWorkerBuilder#setProgressUpdater(androidx.work.ProgressUpdater)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/ProgressUpdater updater)`

Sets the `https://developer.android.com/reference/androidx/work/ProgressUpdater` to be used to construct the `https://developer.android.com/reference/androidx/work/ListenableWorker`.
`@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/testing/TestListenableWorkerBuilder<W>` `https://developer.android.com/reference/androidx/work/testing/TestListenableWorkerBuilder#setRunAttemptCount(int)(int runAttemptCount)`

Sets the initial run attempt count for this work.
`@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/testing/TestListenableWorkerBuilder<W>` `https://developer.android.com/reference/androidx/work/testing/TestListenableWorkerBuilder#setTags(java.util.List<java.lang.String>)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/java/lang/String.html> tags)`

Sets the tags associated with this unit of work.
`@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/testing/TestListenableWorkerBuilder<W>` `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 24)
https://developer.android.com/reference/androidx/work/testing/TestListenableWorkerBuilder#setTriggeredContentAuthorities(java.util.List<java.lang.String>)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/java/lang/String.html> authorities)`

Sets the authorities for content `https://developer.android.com/reference/android/net/Uri.html`'s associated with this unit of work.
`@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/testing/TestListenableWorkerBuilder<W>` `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 24)
https://developer.android.com/reference/androidx/work/testing/TestListenableWorkerBuilder#setTriggeredContentUris(java.util.List<android.net.Uri>)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/android/net/Uri.html> contentUris)`

Sets the list of Content `https://developer.android.com/reference/android/net/Uri.html`s associated with this unit of work.
`@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/testing/TestListenableWorkerBuilder<W>` `https://developer.android.com/reference/androidx/work/testing/TestListenableWorkerBuilder#setWorkerFactory(androidx.work.WorkerFactory)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/WorkerFactory workerFactory)`

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

## Public methods

### from

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

```
public static @NonNull TestWorkerBuilder<Worker> from(
    @NonNull Context context,
    @NonNull WorkRequest workRequest,
    @NonNull Executor executor
)
```

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

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | The `https://developer.android.com/reference/android/content/Context.html` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/WorkRequest workRequest` | The `https://developer.android.com/reference/androidx/work/WorkRequest` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/concurrent/Executor.html executor` | The `https://developer.android.com/reference/java/util/concurrent/Executor.html` |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/testing/TestWorkerBuilder<https://developer.android.com/reference/androidx/work/Worker>` | The new instance of a `https://developer.android.com/reference/androidx/work/testing/TestWorkerBuilder` |

### from

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

```
public static @NonNull TestWorkerBuilder<W> <W extends Worker> from(
    @NonNull Context context,
    @NonNull Class<W> workerClass,
    @NonNull Executor executor
)
```

Creates a new instance of a `https://developer.android.com/reference/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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | The `https://developer.android.com/reference/android/content/Context.html` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<W> workerClass` | The subtype of `https://developer.android.com/reference/androidx/work/Worker` being built |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/concurrent/Executor.html executor` | The `https://developer.android.com/reference/java/util/concurrent/Executor.html` |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/testing/TestWorkerBuilder<W>` | The new instance of a `https://developer.android.com/reference/androidx/work/testing/TestWorkerBuilder` |