Klitos Kyriacou
06/19/2023, 4:54 PMimport io.kotest.core.spec.style.FreeSpec
import io.kotest.datatest.withData
import io.kotest.matchers.shouldBe
fun foo(i: Int) = i + 1
class `this works ok`: FreeSpec({
withData(1, 2, 3) { i ->
foo(i) shouldBe i + 1
}
})
class `this doesn't work`: FreeSpec({
"some context" {
withData(1, 2, 3) { i ->
foo(i) shouldBe i + 1
}
}
})
The second test class fails with io.kotest.core.spec.InvalidDslException: Cannot add a root test after the spec has been instantiated: 1
Emil Kantis
06/19/2023, 5:12 PMwithData
inside a leaf, only at root level or inside a container.Klitos Kyriacou
06/19/2023, 5:20 PMwithData
, the assertions must be inside a leaf (which may optionally be inside a container), but when using withData
the assertions must be directly under a container.Emil Kantis
06/19/2023, 5:24 PMwithData
generates a leaf for each row under the hood, so they're not in a container. But I understand that it can be perceived as being directly under the container