# WorkManagerTestInitHelper.ExecutorsMode

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/WorkManagerTestInitHelper.java+class:androidx.work.testing.WorkManagerTestInitHelper.ExecutorsMode) Added in [2.9.0](https://developer.android.com/jetpack/androidx/releases/work#2.9.0)

*** ** * ** ***

<br />

```
public enum WorkManagerTestInitHelper.ExecutorsMode
```

<br />

*** ** * ** ***

Modes that control which executors are used in tests.

## Summary

| ### Enum Values |
|---|---|
| `https://developer.android.com/reference/androidx/work/testing/WorkManagerTestInitHelper.ExecutorsMode#LEGACY_OVERRIDE_WITH_SYNCHRONOUS_EXECUTORS` | Preserve old behavior of `https://developer.android.com/reference/androidx/work/testing/WorkManagerTestInitHelper#initializeTestWorkManager(android.content.Context)` and `https://developer.android.com/reference/androidx/work/testing/WorkManagerTestInitHelper#initializeTestWorkManager(android.content.Context,androidx.work.Configuration)`. |
| `https://developer.android.com/reference/androidx/work/testing/WorkManagerTestInitHelper.ExecutorsMode#PRESERVE_EXECUTORS` | Use executors as they are configured in passed `https://developer.android.com/reference/androidx/work/Configuration` and preserving real main thread. |
| `https://developer.android.com/reference/androidx/work/testing/WorkManagerTestInitHelper.ExecutorsMode#USE_TIME_BASED_SCHEDULING` | Like `https://developer.android.com/reference/androidx/work/testing/WorkManagerTestInitHelper.ExecutorsMode#PRESERVE_EXECUTORS`, but uses the real Clock and RunnableScheduler in the provided `https://developer.android.com/reference/androidx/work/Configuration` instead of the `https://developer.android.com/reference/androidx/work/testing/TestDriver` setDelayMet() methods to run scheduled work. |

| ### Public methods |
|---|---|
| `static https://developer.android.com/reference/androidx/work/testing/WorkManagerTestInitHelper.ExecutorsMode` | `https://developer.android.com/reference/androidx/work/testing/WorkManagerTestInitHelper.ExecutorsMode#valueOf(java.lang.String)(https://developer.android.com/reference/java/lang/String.html name)` Returns the enum constant of this type with the specified name. |
| `static WorkManagerTestInitHelper.ExecutorsMode[]` | `https://developer.android.com/reference/androidx/work/testing/WorkManagerTestInitHelper.ExecutorsMode#values()()` 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 `https://developer.android.com/reference/androidx/work/testing/WorkManagerTestInitHelper#initializeTestWorkManager(android.content.Context)` and `https://developer.android.com/reference/androidx/work/testing/WorkManagerTestInitHelper#initializeTestWorkManager(android.content.Context,androidx.work.Configuration)`.

In this mode `https://developer.android.com/reference/androidx/work/testing/SynchronousExecutor` is used instead of main thread. Similarly, `https://developer.android.com/reference/androidx/work/testing/SynchronousExecutor` is used as `https://developer.android.com/reference/androidx/work/Configuration#getTaskExecutor()`, unless `https://developer.android.com/reference/androidx/work/Configuration#getTaskExecutor()` was explicitly set in `configuration` passed in `https://developer.android.com/reference/androidx/work/testing/WorkManagerTestInitHelper#initializeTestWorkManager(android.content.Context,androidx.work.Configuration,androidx.work.testing.WorkManagerTestInitHelper.ExecutorsMode)`

### PRESERVE_EXECUTORS

```
WorkManagerTestInitHelper.ExecutorsMode WorkManagerTestInitHelper.ExecutorsMode.PRESERVE_EXECUTORS
```

Use executors as they are configured in passed `https://developer.android.com/reference/androidx/work/Configuration` and preserving real main thread.

### USE_TIME_BASED_SCHEDULING

```
WorkManagerTestInitHelper.ExecutorsMode WorkManagerTestInitHelper.ExecutorsMode.USE_TIME_BASED_SCHEDULING
```

Like `https://developer.android.com/reference/androidx/work/testing/WorkManagerTestInitHelper.ExecutorsMode#PRESERVE_EXECUTORS`, but uses the real Clock and RunnableScheduler in the provided `https://developer.android.com/reference/androidx/work/Configuration` instead of the `https://developer.android.com/reference/androidx/work/testing/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. `https://developer.android.com/reference/androidx/work/testing/TestDriver#setInitialDelayMet(java.util.UUID)` and `https://developer.android.com/reference/androidx/work/testing/TestDriver#setPeriodDelayMet(java.util.UUID)` 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 |
|---|---|
| `https://developer.android.com/reference/androidx/work/testing/WorkManagerTestInitHelper.ExecutorsMode` | the enum constant with the specified name |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | 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 |