KmpWorkerTestRule
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"))
}
}Content copied to clipboard