Looks like `withData()` in isolation mode `Instanc...
# kotest
l
Looks like
withData()
in isolation mode
InstancePerTest
and
InstancePerLeaf
doesn't support multiple arguments when one of them is random (or otherwise generated, I'm using Instancio) and the others are based on the first one:
Copy code
val a = Random.nextInt().toString()
val b = "101$a"
val c = "010$a"

withData(a, b, c) { a -> println("withData: $a") }
prints only the first argument (the test doesn't run for
b
and
c
):
Copy code
withData: 1234664241
Kotest 5.9.1, isolationMode = InstancePerTest Test is nested in a FreeSpec
This minimal reproducer throws `NoSuchElementException`:
Copy code
class MyTest : StringSpec({
    isolationMode = InstancePerTest

    val a = Random.nextInt().toString()
    val b = "101$a"
    val c = "010$a"

    withData(a, b, c) { t -> println("withData: $t") }
})
exception.log
When using
InstancePerLeaf
instead, the test doesn't throw, but only executes the test with the first argument.
Only with
SingleInstance
it works as expected.
Looks like the problem has been caused by the arguments not being stable (I suppose it means that the arguments cannot be resolved after the test is done). I could work around the problem by assigning explicit names for each of the arguments:
Copy code
withData(
    mapOf(
        "Random" to Random.nextInt().toString(),
        // ...
    )
) {
    // ...
}
Would it be possible to give a more clear error in this case?
s
I think it must be because the test names are changing between instances, so I think we could throw an error saying the test couldn't be found when the next spec is instantiated
thank you color 1