# TestDriver

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

*** ** * ** ***


```
public interface TestDriver
```

<br />

*** ** * ** ***

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

## Summary

| ### Public methods |
|---|---|
| `abstract void` | `https://developer.android.com/reference/androidx/work/testing/TestDriver#setAllConstraintsMet(java.util.UUID)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/UUID.html workSpecId)` Tells `https://developer.android.com/reference/androidx/work/testing/TestDriver` to pretend that all constraints on the `https://developer.android.com/reference/androidx/work/WorkRequest` with the given `workSpecId` are met. |
| `abstract void` | `https://developer.android.com/reference/androidx/work/testing/TestDriver#setInitialDelayMet(java.util.UUID)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/UUID.html workSpecId)` Tells `https://developer.android.com/reference/androidx/work/testing/TestDriver` to pretend that the initial delay the `https://developer.android.com/reference/androidx/work/OneTimeWorkRequest` with the given `workSpecId` is met. |
| `abstract void` | `https://developer.android.com/reference/androidx/work/testing/TestDriver#setPeriodDelayMet(java.util.UUID)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/UUID.html workSpecId)` Tells `https://developer.android.com/reference/androidx/work/testing/TestDriver` to pretend that the period delay on the `https://developer.android.com/reference/androidx/work/PeriodicWorkRequest` with the given `workSpecId` is met. |
| `default void` | `https://developer.android.com/reference/androidx/work/testing/TestDriver#stopRunningWorkWithReason(java.util.UUID,int)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/UUID.html workSpecId, int reason)` Tells `https://developer.android.com/reference/androidx/work/testing/TestDriver` to pretend that a running worker should be stopped with the provided `https://developer.android.com/reference/androidx/work/StopReason`. |

## Public methods

### setAllConstraintsMet

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

```
abstract void setAllConstraintsMet(@NonNull UUID workSpecId)
```

Tells `https://developer.android.com/reference/androidx/work/testing/TestDriver` to pretend that all constraints on the `https://developer.android.com/reference/androidx/work/WorkRequest` with the given `workSpecId` are met. This may trigger execution of the work.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/UUID.html workSpecId` | The `https://developer.android.com/reference/androidx/work/WorkRequest`'s id |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `workSpecId` is not enqueued |

### setInitialDelayMet

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

```
abstract void setInitialDelayMet(@NonNull UUID workSpecId)
```

Tells `https://developer.android.com/reference/androidx/work/testing/TestDriver` to pretend that the initial delay the `https://developer.android.com/reference/androidx/work/OneTimeWorkRequest` with the given `workSpecId` is met. This may trigger execution of the work.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/UUID.html workSpecId` | The `https://developer.android.com/reference/androidx/work/OneTimeWorkRequest`'s id |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `workSpecId` is not enqueued |

### setPeriodDelayMet

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

```
abstract void setPeriodDelayMet(@NonNull UUID workSpecId)
```

Tells `https://developer.android.com/reference/androidx/work/testing/TestDriver` to pretend that the period delay on the `https://developer.android.com/reference/androidx/work/PeriodicWorkRequest` with the given `workSpecId` is met. This may trigger execution of the work.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/UUID.html workSpecId` | The `https://developer.android.com/reference/androidx/work/PeriodicWorkRequest`'s id |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `workSpecId` is not enqueued |

### stopRunningWorkWithReason

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

```
default void stopRunningWorkWithReason(@NonNull UUID workSpecId, int reason)
```

Tells `https://developer.android.com/reference/androidx/work/testing/TestDriver` to pretend that a running worker should be stopped with the provided `https://developer.android.com/reference/androidx/work/StopReason`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/UUID.html workSpecId` | The `https://developer.android.com/reference/androidx/work/WorkRequest`'s id |
| `int reason` | The `https://developer.android.com/reference/androidx/work/StopReason` that will be available to the worker Value is one of the following: - `-512` - `-256` - `-128` - `1` - `2` - `3` - `4` - `5` - `6` - `7` - `8` - `9` - `10` - `11` - `12` - `13` - `14` - `15` <br /> |