androidx.work.testing
WorkManager Testing is a library for testing app code that runs using WorkManager.
This testing library provides a way to manually initialize WorkManager for tests by using androidx.work.testing.WorkManagerTestInitHelper. Once initialized, you can use getTestDriver to drive constraints and timing-related triggers for your background work.
For ease of testing, this library defaults to using a synchronous java.util.concurrent.Executor; you can change this in the androidx.work.Configuration if you wish.
Interfaces
TestDriver |
Additional functionality exposed for |
Classes
SynchronousExecutor |
Is an implementation of a |
TestListenableWorkerBuilder |
Builds instances of |
TestWorkerBuilder |
Builds instances of |
WorkManagerTestInitHelper |
Helps initialize |
Enums
WorkManagerTestInitHelper.ExecutorsMode |
Modes that control which executors are used in tests. |
Top-level functions summary
inline TestListenableWorkerBuilder<W> |
<W : ListenableWorker> TestListenableWorkerBuilder(Builds an instance of |
inline TestWorkerBuilder<W> |
<W : Worker> TestWorkerBuilder(Builds an instance of |
Top-level functions
TestListenableWorkerBuilder
inline fun <W : ListenableWorker> TestListenableWorkerBuilder(
context: Context,
inputData: Data = Data.EMPTY,
tags: List<String> = emptyList(),
runAttemptCount: Int = 1,
triggeredContentUris: List<Uri> = emptyList(),
triggeredContentAuthorities: List<String> = emptyList()
): TestListenableWorkerBuilder<W>
Builds an instance of TestListenableWorkerBuilder.
| Parameters | |
|---|---|
<W : ListenableWorker> |
The subtype of |
context: Context |
The application |
inputData: Data = Data.EMPTY |
The input data for the |
tags: List<String> = emptyList() |
The tags associated with this |
runAttemptCount: Int = 1 |
The run attempt count of the |
triggeredContentUris: List<Uri> = emptyList() |
The list of triggered content |
triggeredContentAuthorities: List<String> = emptyList() |
The list of triggered content authorities |
| Returns | |
|---|---|
TestListenableWorkerBuilder<W> |
The instance of |
TestWorkerBuilder
inline fun <W : Worker> TestWorkerBuilder(
context: Context,
executor: Executor,
inputData: Data = Data.EMPTY,
tags: List<String> = emptyList(),
runAttemptCount: Int = 1,
triggeredContentUris: List<Uri> = emptyList(),
triggeredContentAuthorities: List<String> = emptyList()
): TestWorkerBuilder<W>
Builds an instance of TestWorkerBuilder.
| Parameters | |
|---|---|
<W : Worker> |
The subtype of |
context: Context |
The application |
executor: Executor |
|
inputData: Data = Data.EMPTY |
The input data for the |
tags: List<String> = emptyList() |
The tags associated with this |
runAttemptCount: Int = 1 |
The run attempt count of the |
triggeredContentUris: List<Uri> = emptyList() |
The list of triggered content |
triggeredContentAuthorities: List<String> = emptyList() |
The list of triggered content authorities |
| Returns | |
|---|---|
TestWorkerBuilder<W> |
The instance of |