Manuel Jordan
Manuel Jordan

Reputation: 16299

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

Upvotes: 1

Views: 1935

Answers (2)

Abach42
Abach42

Reputation: 1

Here you get DisplayName in a tree view:

[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] |
[INFO] +-- com.abach42.superhero.functional.controller.SuperheroControllerTest
[INFO] | +-- [OK] Controller action for foo not found returns 404 - 1.267 ss
[INFO] | +-- [OK] Controller action for foo returns superheros - 1.477 ss
[INFO] | +-- [OK] Controller action for bar returns a superhero - 0.126 ss
[INFO] | +-- [OK] Controller action for bar not found returns 404 - 0.019 


<plugin>
    <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin -->
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.2.5</version>
    <dependencies>
      <!-- https://mvnrepository.com/artifact/me.fabriciorby/maven-surefire-junit5-tree-reporter -->
      <dependency>
          <groupId>me.fabriciorby</groupId>
          <artifactId>maven-surefire-junit5-tree-reporter</artifactId>
          <version>1.2.1</version>
      </dependency>
      </dependencies>
      <configuration>
        <argLine>-Xshare:off</argLine>
        <parallel>all</parallel>
        <reportFormat>plain</reportFormat>
        <consoleOutputReporter>
          <disable>true</disable>
        </consoleOutputReporter>
        <statelessTestsetInfoReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporter">
          <disable>false</disable>
          <usePhrasedFileName>false</usePhrasedFileName>
          <usePhrasedClassNameInRunning>true</usePhrasedClassNameInRunning>
          <usePhrasedClassNameInTestCaseSummary>true</usePhrasedClassNameInTestCaseSummary>
        </statelessTestsetInfoReporter>
      </configuration>
  </plugin>

Upvotes: 0

armandino
armandino

Reputation: 18562

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>

Upvotes: 3

Related Questions