https://kotlinlang.org logo
#kotest
Title
# kotest
k

Kirill Zhukov

03/27/2024, 6:00 PM
What's the benefit of using
coroutineTestScope
in kotest over kotlin's
runTest
directly? Is the main benefit that I can set
coroutineTestScope = true
once on entire spec instead of having to call
runTest
on each individual test? Anything else I'm missing?
l

LeoColman

03/27/2024, 6:06 PM
Just double checking: If your code is not related to testing coroutines, you shouldn't need to touch the coroutines scope. Doesn't really answer your question but might take you out of a rabbit hole 😂
k

Kirill Zhukov

03/27/2024, 6:26 PM
Definitely testing coroutines in my case 🙂
c

CLOVIS

03/28/2024, 9:05 AM
Calling
runTest
inside a Kotest test won't work for some platforms (e.g. JS) because the promise won't be propagated correctly to the parent
On platforms where it does work (e.g. JVM), it creates a completely decorrelated scope that has no relationship whatsoever with the Kotest internal scope, so you cannot use any Kotest configuration for coroutines, and you may have issues with timeouts
k

Kirill Zhukov

03/28/2024, 8:36 PM
Are these differences documented anywhere in Kotest docs by any chance?
c

CLOVIS

03/29/2024, 8:19 AM
I don't know.
s

sam

03/31/2024, 11:11 PM
Saves you use runTest everywhere, kotest provides the scope for you. It also allows you to add blocking = true into the config, and then it will detect non coroutine deadlocks. As well as having other cooperative multitasking timeout support.
today i learned 1
k

Kirill Zhukov

04/04/2024, 10:47 PM
That's very good to know, thanks!