Carmen
04/15/2025, 7:39 AMCarmen
04/15/2025, 4:21 PMDispatchers.setMain(UnconfinedTestDispatcher())
Kartik Prakash
04/16/2025, 11:50 PMStandardTestDispatcher
in your tests.
If you're targeting android & ios there isn't an ideal way to do integration testing i.e tests that run on the device. But there is a tricky way to do it using mokkery.Carmen
04/22/2025, 12:03 PMKartik Prakash
04/23/2025, 6:26 PMclass MyViewModel(val dispatcher: CoroutineDispatcher) : ViewModel() {
fun someFunction() {
viewmodelScope.launch(dispatcher) { ... }
}
}
Kartik Prakash
04/23/2025, 6:29 PMclass MyViewModelTest {
val testDispatcher = StandardTestDispatcher()
val myViewModel = MyViewModel(testDispatcher)
@Test
fun `my viewmodel test`() = runTest {
myViewModel.someFunction()
testDispatcher.scheduler.advanceUntilIdle()
// verify the function call
}
}
Carmen
04/28/2025, 10:06 AM