willowtreeapps / assertk

assertions for kotlin inspired by assertj
MIT License
757 stars 84 forks source link

[JVM] Table to JUnit Jupiter dynamic tests #520

Open Xfel opened 5 months ago

Xfel commented 5 months ago

The big advantage of the Table assertions is that they are a lot simpler to use than comparative options like JUnit's ParameterizedTest.

However one downside in comparison is that the Table Test shows up as a single node in the test report, whereas ParameterizedTest will add an entry for each parameter set. If you have a big table, that makes it rather complicated to see what is failing and what is not. Also, we cannot rerun individual failing rows.

A solution would be to take advantage of JUnit's dynamic tests. Instead of just calling the table forAll function, we could use a setup like this:

@TestFactory
fun myTableTest() = tableOf("a", "b", "result")
    .row(0, 0, 1)
    .row(1, 2, 4)
    .asDynamicTest { a, b, result ->
        assertThat(a + b).isEqualTo(result)
    }

The asDynamicTest function would be an extension function residing in a JVM + JUnit 5 exclusive file.