Junit5's test report output plugin, are there any other better alternatives? Gradle platform or maven platform

Viewed 758

I am learning to use junit5. I followed the tutorial to write some dynamic tests and then run them using gradle. But the test report output by gradle by default is not good enough for me, it does not contain nested test container structure. Is there any alternative that can output a better-formed test report when running dynamic tests? Similar to the intellij idea test report. the code:

    @TestFactory
    Stream<DynamicNode> dynamicTestsWithContainers() {
        return Stream.of("A", "B", "C")
                .map({ input ->
                    dynamicContainer("Container " + input, Stream.of(
                            dynamicTest("not null", { -> assertNotNull(input) }) as DynamicNode,
                            dynamicContainer("properties", Stream.of(
                                    dynamicTest("length > 0", { -> assertTrue(input.length() > 0) }),
                                    dynamicTest("not empty", { -> assertFalse(input.isEmpty()) })
                            ))
                    ))
                })
    }

run with gradle:

html report xml report

run with intellij idea:

intellij idea report

1 Answers

As I found out, maven-surefire-plugin since version 3.0.0 supports better reporting for JUnit5 using JUnit5Xml30StatelessReport. The usage example is given in documentation:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M4</version>
    <configuration>
        <testFailureIgnore>true</testFailureIgnore>
        <statelessTestsetReporter
            implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5Xml30StatelessReporter">
            <disable>false</disable>
            <version>3.0</version>
            <usePhrasedFileName>true</usePhrasedFileName>
            <usePhrasedTestSuiteClassName>true</usePhrasedTestSuiteClassName>
            <usePhrasedTestCaseClassName>true</usePhrasedTestCaseClassName>
            <usePhrasedTestCaseMethodName>true</usePhrasedTestCaseMethodName>
        </statelessTestsetReporter>
    </configuration>
 </plugin>

This reporter respects dynamic test descriptions when usePhrasedXXX parameters are set to true. However, it still does not respect the nested structure (all the tescases are in a flat list).

Related