https://kotlinlang.org logo
Title
k

KotlinLeaner

02/23/2023, 12:02 PM
Hi guys, I want to know what is the difference between
runBlocking
and
runTest
?
t

Troels Lund

02/23/2023, 12:12 PM
Based on the documentation,
runTest
does the same as
runBlocking
, but skips all
delay()
.
k

KotlinLeaner

02/23/2023, 12:13 PM
Thanks for guidance..
j

Joffrey

02/23/2023, 1:21 PM
Also,
runTest
is multiplatform and can be used in Kotlin/JS tests
Also, the test dispatcher allows you to control time, advance until all nested coroutines are idle, etc. A bunch of nice features you might need in tests
k

KotlinLeaner

02/23/2023, 1:26 PM
Okk thanks for gudiance
j

Joffrey

02/23/2023, 1:28 PM
But be aware that skipping delays is not necessarily desirable, and may bite you if you interact with external systems, or code that use a "real" dispatcher with real time. For instance, you may notice that
withTimeout
instantly times out in those cases.