https://kotlinlang.org logo
#compose-android
Title
# compose-android
v

vide

11/21/2023, 4:30 PM
Has there been talk about managing time of coroutines in integrated tests? I would like to manipulate clocks of coroutine schedulers for testing behaviour involving timers (in viewmodels, for example) in a predictable way. I don't want to inject a test scheduler directly because I want to verify UI state before and after delays, but skip them when needed from the test itself. I couldn't find any relevant docs
For example, there's a page with a viewmodel that launches a delay() to a viewModelScope. I want to verify initial UI state, then skip the delay, and then verify the new UI state after changes in the vm.
It seems like the existing test tools are mostly geared towards controlling unit tests
v

vide

11/21/2023, 6:02 PM
I think the TestCoroutineScheduler will skip delays automatically though? https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scheduler/ Or am I confused about how the coroutine dispatchers/schedulers work?
m

mkrussel

11/21/2023, 7:39 PM
The scheduler can auto skip delays or not. This is the best description I've seen on how it works. https://github.com/Kotlin/kotlinx.coroutines/issues/1266#issuecomment-504234816
Now the main problem I would see is the test dispatchers will probably not run on the main thread, but I don't know if you need that for you integration tests.