Hello! i'm trying to write a simple test using the...
# kotest
k
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
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
Thanks, it worked, behaviour spec has a property, so the result looks like this:
Copy code
internal class Test : BehaviorSpec({

    coroutineTestScope = true

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