TestDriver


public interface TestDriver


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

Summary

Public methods

abstract void

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

abstract void

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

abstract void

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

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

Tells TestDriver to pretend that a running worker should be stopped with the provided StopReason.

Public methods

setAllConstraintsMet

Added in 1.0.0
abstract void setAllConstraintsMet(@NonNull UUID workSpecId)

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
@NonNull UUID workSpecId

The androidx.work.WorkRequest's id

Throws
java.lang.IllegalArgumentException

if workSpecId is not enqueued

setInitialDelayMet

Added in 1.0.0
abstract void setInitialDelayMet(@NonNull UUID workSpecId)

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
@NonNull UUID workSpecId

The androidx.work.OneTimeWorkRequest's id

Throws
java.lang.IllegalArgumentException

if workSpecId is not enqueued

setPeriodDelayMet

Added in 1.0.0
abstract void setPeriodDelayMet(@NonNull UUID workSpecId)

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
@NonNull UUID workSpecId

The androidx.work.PeriodicWorkRequest's id

Throws
java.lang.IllegalArgumentException

if workSpecId is not enqueued

stopRunningWorkWithReason

Added in 2.11.0-beta01
default void stopRunningWorkWithReason(@NonNull UUID workSpecId, int reason)

Tells TestDriver to pretend that a running worker should be stopped with the provided StopReason.

Parameters
@NonNull UUID workSpecId

The androidx.work.WorkRequest's id

int reason

The StopReason that will be available to the worker