There are a few options, but why do use launch(UI)
right inside doSomething
? It is going to be easier to test if that was a suspend fun doSomething() = withContext(UI) { … }
. Then you’d simply invoke it from your test with UI
replaced by coroutineContext
of your runBlocking
and it would work as desired, even with delays.
1 Like