Regarding data-driven testing, Kotest documents on...
# kotest
k
Regarding data-driven testing, Kotest documents only the
withData
usage, but I've also seen people using
forAll
,
table
and
row
, for example at https://proandroiddev.com/data-driven-testing-with-kotlintest-a07ac60e70fc. Are the latter not recommended, perhaps superseded by
withData
? Or is it that
forAll
etc are too new to be documented but may replace
withData
in the future?
w
In the past I migrated away from
forAll
due to performance issues caused by reflectively determining parameters names https://github.com/kotest/kotest/blob/3646c5eee03e8807f6e3cd7415bf61ac49182ccd/kotest-assertions/kotest-assertions-shared/src/commonMain/kotlin/io/kotest/data/forAll2.kt#L6-L7
I see this is solved by
Table
though? In any case, I don't know about Kotest guidelines, but at $work we just went with a
listOf(OurCustomTestCaseDataClass).forEach { describe("description" { } }
. It's not a lot more overhead to write, IDE support is faster (less generics compared to
Row
), and we can clearly name arguments in custom data class.
👍 1
e
I personally prefer
withData
, but beware the slight but significant inconsistency regarding lifecycle hooks which currently exists (addressed by #3300) between tests created by
withData
vs a regular test. I assumed that
withData
was intended do replace
forAll
(which clashes naming-wise with the prop.testing function, as well as the collection inspection), but I haven't seen any moves to deprecate
forAll
so not sure if it's actually planned.