Google is committed to advancing racial equity for Black communities. See how.

TestDriver

interface TestDriver
androidx.work.testing.TestDriver

Additional functionality exposed for androidx.work.WorkManager that are useful in the context of testing.

Summary

Public methods

abstract Unit
setAllConstraintsMet(@NonNull workSpecId: UUID)

Tells TestDriver to pretend that all constraints on the androidx.work.WorkRequest with the given workSpecId are met.

abstract Unit
setInitialDelayMet(@NonNull workSpecId: UUID)

Tells TestDriver to pretend that the initial delay the androidx.work.OneTimeWorkRequest with the given workSpecId is met.

abstract Unit
setPeriodDelayMet(@NonNull workSpecId: UUID)

Tells TestDriver to pretend that the period delay on the androidx.work.PeriodicWorkRequest with the given workSpecId is met.

Public methods

setAllConstraintsMet

abstract fun setAllConstraintsMet(@NonNull workSpecId: UUID): Unit

Tells TestDriver to pretend that all constraints on the androidx.work.WorkRequest with the given workSpecId are met. This may trigger execution of the work.

Parameters
workSpecId UUID: The androidx.work.WorkRequest's id
Exceptions
IllegalArgumentException if workSpecId is not enqueued

setInitialDelayMet

abstract fun setInitialDelayMet(@NonNull workSpecId: UUID): Unit

Tells TestDriver to pretend that the initial delay the androidx.work.OneTimeWorkRequest with the given workSpecId is met. This may trigger execution of the work.

Parameters
workSpecId UUID: The androidx.work.OneTimeWorkRequest's id
Exceptions
IllegalArgumentException if workSpecId is not enqueued

setPeriodDelayMet

abstract fun setPeriodDelayMet(@NonNull workSpecId: UUID): Unit

Tells TestDriver to pretend that the period delay on the androidx.work.PeriodicWorkRequest with the given workSpecId is met. This may trigger execution of the work.

Parameters
workSpecId UUID: The androidx.work.PeriodicWorkRequest's id
Exceptions
IllegalArgumentException if workSpecId is not enqueued