KmpWorkerTestRule

class KmpWorkerTestRule : TestRule

JUnit4 test rule that sets up a test environment for KMPWorker on Android.

Initializes WorkManager in test mode and provides a FakeKmpWorker for assertions. Automatically resets state between tests.

class MyWorkerTest {
@get:Rule
val kmpWorkerRule = KmpWorkerTestRule()

@Test
fun testSync() = runTest {
kmpWorkerRule.worker.register("sync") { repo.sync() }
kmpWorkerRule.worker.enqueue(TaskRequest("sync", TaskType.OneTime))
assertEquals(TaskState.Success, kmpWorkerRule.worker.lastStateFor("sync"))
}
}

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

The fake network monitor — control online/offline state.

Link copied to clipboard

The fake worker for testing — register handlers and assert state.

Functions

Link copied to clipboard
open override fun apply(base: Statement, description: Description): Statement