Klitos Kyriacou
06/19/2023, 4:35 PMio.kotest.data.forAll
but it throws an exception when I use withData
. I presume the latter is the preferred way for data-driven tests while the former is legacy (as I couldn't find it in the latest documentation). Full reproducible example in the thread.Klitos Kyriacou
06/19/2023, 4:37 PMimport io.kotest.core.spec.style.FreeSpec
import io.kotest.data.forAll
import io.kotest.data.row
import io.kotest.datatest.withData
import io.kotest.matchers.shouldBe
fun foo() = 42
fun bar() = 42
class Test: FreeSpec({
"forAll" {
forAll(
row(::foo),
row(::bar)
) { f ->
f() shouldBe 42
}
}
"withData" {
withData(
::foo,
::bar
) { f ->
f() shouldBe 42
}
}
})
forAll
passes.
withData
throws UnsupportedOperationException: This class is an internal synthetic class generated by the Kotlin compiler, such as an anonymous class for a lambda, a SAM wrapper, a callable reference, etc. It's not a Kotlin class or interface, so the reflection library has no idea what declarations it has. Please use Java reflection to inspect this class: class Test$1$2$1
Emil Kantis
06/19/2023, 5:09 PMfun foo() = 42
fun bar() = 42
class Test : FreeSpec(
{
"forAll" {
forAll(
row(::foo),
row(::bar),
) { f ->
f() shouldBe 42
}
}
"withData" - {
withData(
nameFn = { it.name },
first = ::foo,
second = ::bar,
) { f ->
f() shouldBe 42
}
}
},
)
Emil Kantis
06/19/2023, 5:11 PM