Skip to content

[JVM] Table to JUnit Jupiter dynamic tests #520

Open
@Xfel

Description

@Xfel

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions