https://kotlinlang.org logo
#kotest
Title
# kotest
m

mcpiroman

04/11/2022, 4:19 PM
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

sam

04/11/2022, 4:38 PM
What output would you prefer to see ?
m

mcpiroman

04/11/2022, 5:19 PM
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

sam

04/11/2022, 5:23 PM
You can nest withData many times
m

mcpiroman

04/11/2022, 5:27 PM
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

sam

04/11/2022, 5:58 PM
you could do manual for each loops then create the tests inside however you need to
18 Views