WorkManagerTestInitHelper.ExecutorsMode


public enum WorkManagerTestInitHelper.ExecutorsMode


Modes that control which executors are used in tests.

Summary

Enum Values

LEGACY_OVERRIDE_WITH_SYNCHRONOUS_EXECUTORS

Preserve old behavior of initializeTestWorkManager and initializeTestWorkManager.

PRESERVE_EXECUTORS

Use executors as they are configured in passed Configuration and preserving real main thread.

USE_TIME_BASED_SCHEDULING

Like PRESERVE_EXECUTORS, but uses the real Clock and RunnableScheduler in the provided Configuration instead of the TestDriver setDelayMet() methods to run scheduled work.

Public methods

static WorkManagerTestInitHelper.ExecutorsMode

Returns the enum constant of this type with the specified name.

static WorkManagerTestInitHelper.ExecutorsMode[]

Returns an array containing the constants of this enum type, in the order they're declared.

Enum Values

LEGACY_OVERRIDE_WITH_SYNCHRONOUS_EXECUTORS

WorkManagerTestInitHelper.ExecutorsMode WorkManagerTestInitHelper.ExecutorsMode.LEGACY_OVERRIDE_WITH_SYNCHRONOUS_EXECUTORS

Preserve old behavior of initializeTestWorkManager and initializeTestWorkManager.

In this mode SynchronousExecutor is used instead of main thread. Similarly, SynchronousExecutor is used as getTaskExecutor, unless getTaskExecutor was explicitly set in configuration passed in initializeTestWorkManager

PRESERVE_EXECUTORS

WorkManagerTestInitHelper.ExecutorsMode WorkManagerTestInitHelper.ExecutorsMode.PRESERVE_EXECUTORS

Use executors as they are configured in passed Configuration and preserving real main thread.

USE_TIME_BASED_SCHEDULING

WorkManagerTestInitHelper.ExecutorsMode WorkManagerTestInitHelper.ExecutorsMode.USE_TIME_BASED_SCHEDULING

Like PRESERVE_EXECUTORS, but uses the real Clock and RunnableScheduler in the provided Configuration instead of the TestDriver setDelayMet() methods to run scheduled work.

Work will be passed to RunnableScheduler with appropriate time-based delay, and the RunnableScheduler must reschedule the work itself when the clock delay has passed. setInitialDelayMet and setPeriodDelayMet throw exceptions when this configuration is used.

This mode is intended for integrated fake clock / schedule test frameworks, eg. kotlinx.coroutines.test.StandardTestDispatcherImpl with kotlinx.coroutines.test.TestCoroutineScheduler

Public methods

valueOf

Added in 2.9.0
public static WorkManagerTestInitHelper.ExecutorsMode valueOf(String name)

Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Returns
WorkManagerTestInitHelper.ExecutorsMode

the enum constant with the specified name

Throws
java.lang.IllegalArgumentException

if this enum type has no constant with the specified name

values

Added in 2.9.0
public static WorkManagerTestInitHelper.ExecutorsMode[] values()

Returns an array containing the constants of this enum type, in the order they're declared. This method may be used to iterate over the constants.

Returns
WorkManagerTestInitHelper.ExecutorsMode[]

an array containing the constants of this enum type, in the order they're declared