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

klimchuk daniil

11/30/2023, 5:00 PM
Hello! i'm trying to write a simple test using the TestScope and get an exception: "IllegalStateException: CoroutineDispatcher is not a TestDispatcher" Here's my simplified test:
Copy code
Given("x") {
    testScope.launch {
        1 + 1
    }
    testScope.testCoroutineScheduler.advanceUntilIdle()
}
Is this api supported or am i misusing it?
w

Wesley Hartford

11/30/2023, 5:44 PM
You have to specify in your configuration that you want to use a test scheduler. I've only done this using the
FunSpec
style, but it looks something like this:
Copy code
test("using test scheduler").config(coroutineTestScope = true) {
  testCoroutineScheduler.advanceUntilIdle()
}
You can specify that configuration in other places, I'm not sure what all the options are.
k

klimchuk daniil

12/01/2023, 7:46 PM
Thanks, it worked, behaviour spec has a property, so the result looks like this:
Copy code
internal class Test : BehaviorSpec({

    coroutineTestScope = true

    Given("X") {
        ...
    }
}
9 Views