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



JUnit 平台附带的控制台启动器(来自 JUnit 5(在最后生成了一个相当不错的摘要视图。然而,Maven Surefire插件有一个非常简单的输出。

是否可以使用类似于启动创建的 Surefire 输出进行创建?

我目前的解决方法是禁用 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>

我知道这是一个古老的话题,但这个话题是我在 2 年前开发这个扩展的原因: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>

奇迹发生了

目前,Surefire正在开发嵌入式Surefire功能的扩展1,以及支持JUnit5 DisplayName的独立扩展。 其中一个扩展是测试集信息的控制台记录器。与 2 中的控制台非常相似的输出也可能支持。

扩展是一组Java抽象,Surefire/Failsafe插件将包含这些抽象的默认实现。其他渐进式扩展实现,其输出类似于 2,将善意地要求用户支持 Surefire 项目,以便在他们自己的 GitHub 存储库(而不是 ASF(中实现扩展。欢迎Surefire在ASF Maven Surefire网页上列出这些扩展的所有第三方实现。

通过这种方式(开闭 DP(,我们相信我们为您提供一定的自由来更改插件的行为,而无需报告真正的 Jira 问题,也无需等待新功能发布。

当然。

随意打开一个功能请求以扩展当前摘要输出 https://issues.apache.org/jira/projects/SUREFIRE/issue 也许是针对 https://github.com/apache/maven-surefire 的拉取请求 ;-(

最新更新