mavenjunitmaven-3junit5maven-surefire-plugin

Maven: How show the @DisplayName?


Using JUnit 5, about @DisplayName, through either Eclipse or STS4 appears the respective description, it does not matter if the @Test method passes or fails. Until here all work as expected.

Through Maven how could be possible show the display name too? Currently does not show nothing and test passes/fails as expected, about the surefire-plugin it is declared as:

      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.2</version>
      </plugin>

The purpose is enhanced the report. Through either the terminal or CI


Solution

  • According to the documentation, you need to configure the plugin as shown below. However, this requires surefire plugin version 3.0.0-M4 or greater, so you will need to upgrade from 2.22.2 to use it.

    <build>
        <plugins>
            ...
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <statelessTestsetReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5Xml30StatelessReporter">
                        <disable>false</disable>
                        <version>3.0</version>
                        <usePhrasedFileName>false</usePhrasedFileName>
                        <usePhrasedTestSuiteClassName>true</usePhrasedTestSuiteClassName>
                        <usePhrasedTestCaseClassName>true</usePhrasedTestCaseClassName>
                        <usePhrasedTestCaseMethodName>true</usePhrasedTestCaseMethodName>
                    </statelessTestsetReporter>
                    <consoleOutputReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5ConsoleOutputReporter">
                        <disable>false</disable>
                        <encoding>UTF-8</encoding>
                        <usePhrasedFileName>false</usePhrasedFileName>
                    </consoleOutputReporter>
                    <statelessTestsetInfoReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoReporter">
                        <disable>false</disable>
                        <usePhrasedFileName>false</usePhrasedFileName>
                        <usePhrasedClassNameInRunning>true</usePhrasedClassNameInRunning>
                        <usePhrasedClassNameInTestCaseSummary>true</usePhrasedClassNameInTestCaseSummary>
                    </statelessTestsetInfoReporter>
                </configuration>
            </plugin>
        </plugins>
    </build>