Android Dev Summit, October 23-24: two days of technical content, directly from the Android team. Sign-up for livestream updates.

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