使用 Surefire 生成树输出,如 JUnit 5 控制台启动器

Mic*_*fel 7 java junit5

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?

Fab*_*oto 6

我知道这是一个老话题,但这个话题是我两年前开发这个扩展的原因: https: //github.com/fabriciorby/maven-surefire-junit5-tree-reporter

基本上,要获取树输出,请将其添加到 pom.xml 中:

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M7</version>
    <dependencies>
        <dependency>
            <groupId>me.fabriciorby</groupId>
            <artifactId>maven-surefire-junit5-tree-reporter</artifactId>
            <version>1.0.1</version>
        </dependency>
    </dependencies>
    <configuration>
        <reportFormat>plain</reportFormat>
        <consoleOutputReporter>
            <disable>true</disable>
        </consoleOutputReporter>
        <statelessTestsetInfoReporter
                implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporterUnicode">
        </statelessTestsetInfoReporter>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

奇迹发生了


ram*_*ion 5

我当前的解决方法是禁用 Surefire 并使用exec-maven-plugin手动运行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>
Run Code Online (Sandbox Code Playgroud)