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

Alexandre Brown

06/07/2022, 1:16 PM
Hello, is using
runTest
still needed when using Kotest with
testCoroutineDispatcher = true
? Context : I would usually have a class with
coroutineScope: CoroutineScope
in the constructor
Copy code
class MyClass(private val coroutineScope: CoroutineScope): CoroutineScope by coroutineScope { }
then in my test I would do something like this :
Copy code
"myTest using string spec" {
    runTest {
        val myClass = MyClass(this)
    }
}
So that it uses the Coroutine scope from
runTest
. I see that
StringSpec
has a test scope so that I can do the same but without wrapping my test with
runTest
, is it safe to do so? I want to ensure the are no coroutines leaks between test to avoid flaky tests.
Copy code
"myTest using string spec" {
    val myClass = MyClass(this)
}
s

sam

06/07/2022, 8:43 PM
Kotest will handle all the coroutines for you.
Any errors and it will kill child coroutines etc.
a

Alexandre Brown

06/07/2022, 8:43 PM
That is awesome! Thanks a lot @sam
47 Views