Produce tree output with Surefire like the JUnit 5

2019-06-24 02:02发布

问题:

The Console Launcher that comes with JUnit Platform (from JUnit 5) produces a quite nice summary view at the end. The Maven Surefire plugin, however, has a very simple output.

Is it possible to create with Surefire output similar to what the launches creates?

回答1:

My current workaround is to disable surefire and use exec-maven-plugin to manually run ConsoleLauncher:

<!-- disable surefire -->
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version><!-- ... --></version>
  <executions>
    <execution>
      <id>default-test</id>
      <phase>none</phase>
    </execution>
  </executions>
</plugin>
<!-- enable ConsoleLauncher -->
<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <version><!-- ... --></version>
  <executions>
    <execution>
      <phase>test</phase>
      <goals><goal>java</goal></goals>
      <configuration>
        <mainClass>org.junit.platform.console.ConsoleLauncher</mainClass>
        <arguments>
          <argument>--scan-class-path</argument>
          <argument>${project.build.directory}/test-classes</argument>
        </arguments>
        <classpathScope>test</classpathScope>
      </configuration>
    </execution>
  </executions>
</plugin>
<!-- ... -->
<dependency>
  <groupId>org.junit.platform</groupId>
  <artifactId>junit-platform-console-standalone</artifactId>
  <version><!-- ... --></version>
  <scope>test</scope>
</dependency>


回答2:

Currently Surefire is developig extensions 1 for embedded Surefire features, and a standalone extension supporting JUnit5 DisplayName. One of these extensions is a console logger of testset information. Very similar output to the console in 2 might be possible to support as well then.

The extensions is a set of Java abstractions and Surefire/Failsafe plugins will contain default implementations of these abstractions. The other progressive extension implementations, with the output like in 2, would kindly require users to support Surefire project to implement the extensions in their own GitHub repositories (not in ASF). Surefire is welcome to list all third party implementations of these extensions on the ASF Maven Surefire webpage.

This way (Open-Closed DP) we believe we would provide you with certain freedom to change the behavior of plugins without reporting real Jira issues and without waiting for a new feature release.



回答3:

Sure.

Feel free to open a feature request to extend the current summary output at https://issues.apache.org/jira/projects/SUREFIRE/issue and perhaps a Pull Request against https://github.com/apache/maven-surefire ;-)



标签: java junit5