How do I properly use the same `withData`for multi...
# kotest
m
How do I properly use the same `withData`for multiple tests? 🧵
If I do
Copy code
class Foo : FunSpec({
    context("foo") {
        withData(listOf(1f, -1f, 100000f)) { n ->
            test("add")      { n + 3f    shouldBeExactly n + 1 + 1 + 1 }
            test("multiply") { n * 3f    shouldBeExactly n + n + n }
            test("power")    { n.pow(3f) shouldBeExactly n * n * n }
        }
    }
})
It works, but yields very messy output:
s
What output would you prefer to see ?
m
A one that is anyhow structured. May be: 1.0 • multiply • power -1.0 • multiply • power Or: multiply • 1.0 • -1.0 power: • 1.0 • -1.0
👍 1
s
You can nest withData many times
m
Yes, but it just creates product of the data. I need to provide the same set of data to different tests. In JUnit4 it would be class parametrized tests.
For context I need to test a database like table. The table can be configured with different indices, which do not alter behavior, only performance characteristics. Thus I want to run all table tests with different index configurations.
s
you could do manual for each loops then create the tests inside however you need to