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

*** ** * ** ***


```
interface TestDriver
```

<br />

*** ** * ** ***

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

## Summary

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/work/testing/TestDriver#setAllConstraintsMet(java.util.UUID)(workSpecId: https://developer.android.com/reference/java/util/UUID.html)` Tells `https://developer.android.com/reference/kotlin/androidx/work/testing/TestDriver` to pretend that all constraints on the `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` with the given `workSpecId` are met. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/work/testing/TestDriver#setInitialDelayMet(java.util.UUID)(workSpecId: https://developer.android.com/reference/java/util/UUID.html)` Tells `https://developer.android.com/reference/kotlin/androidx/work/testing/TestDriver` to pretend that the initial delay the `https://developer.android.com/reference/kotlin/androidx/work/OneTimeWorkRequest` with the given `workSpecId` is met. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/work/testing/TestDriver#setPeriodDelayMet(java.util.UUID)(workSpecId: https://developer.android.com/reference/java/util/UUID.html)` Tells `https://developer.android.com/reference/kotlin/androidx/work/testing/TestDriver` to pretend that the period delay on the `https://developer.android.com/reference/kotlin/androidx/work/PeriodicWorkRequest` with the given `workSpecId` is met. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/work/testing/TestDriver#stopRunningWorkWithReason(java.util.UUID,int)(workSpecId: https://developer.android.com/reference/java/util/UUID.html, reason: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Tells `https://developer.android.com/reference/kotlin/androidx/work/testing/TestDriver` to pretend that a running worker should be stopped with the provided `https://developer.android.com/reference/kotlin/androidx/work/StopReason`. |

## Public functions

### setAllConstraintsMet

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

```
fun setAllConstraintsMet(workSpecId: UUID): Unit
```

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

| Parameters |
|---|---|
| `workSpecId: https://developer.android.com/reference/java/util/UUID.html` | The `https://developer.android.com/reference/kotlin/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)

```
fun setInitialDelayMet(workSpecId: UUID): Unit
```

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

| Parameters |
|---|---|
| `workSpecId: https://developer.android.com/reference/java/util/UUID.html` | The `https://developer.android.com/reference/kotlin/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)

```
fun setPeriodDelayMet(workSpecId: UUID): Unit
```

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

| Parameters |
|---|---|
| `workSpecId: https://developer.android.com/reference/java/util/UUID.html` | The `https://developer.android.com/reference/kotlin/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)

```
fun stopRunningWorkWithReason(workSpecId: UUID, reason: Int): Unit
```

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

| Parameters |
|---|---|
| `workSpecId: https://developer.android.com/reference/java/util/UUID.html` | The `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest`'s id |
| `reason: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The `https://developer.android.com/reference/kotlin/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 /> |