Produce tree output with Surefire like the JUnit 5 console launcher

房东的猫 提交于 2019-12-12 11:55:58

问题


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 ;-)



来源:https://stackoverflow.com/questions/50722888/produce-tree-output-with-surefire-like-the-junit-5-console-launcher

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!