Java maven surefire:如何打印正在运行的当前测试?
有没有办法让maven surefire打印它开始的每个单元测试(即测试方法)的名称 比如:Java maven surefire:如何打印正在运行的当前测试?,java,maven,maven-surefire-plugin,Java,Maven,Maven Surefire Plugin,有没有办法让maven surefire打印它开始的每个单元测试(即测试方法)的名称 比如: testFoo: ... passed testBar: ... failed 这有点牵强,但您可以实现一个并将其添加到surefire。有关详细信息,请参阅如何配置它。 package com.example.mavenproject; import org.junit.runner.Description; import org.junit.runner.Result; import org.j
testFoo: ... passed
testBar: ... failed
这有点牵强,但您可以实现一个并将其添加到surefire。有关详细信息,请参阅如何配置它。
package com.example.mavenproject;
import org.junit.runner.Description;
import org.junit.runner.Result;
import org.junit.runner.notification.RunListener;
/**
* @author Paul Verest
*/
public class PrintOutCurrentTestRunListener extends RunListener {
@Override
public void testRunStarted(Description description) throws Exception {
// TODO all methods return null
System.out.println("testRunStarted " + description.getClassName() + " " + description.getDisplayName() + " "
+ description.toString());
}
public void testStarted(Description description) throws Exception {
System.out.println("testStarted "
+ description.toString());
}
public void testFinished(Description description) throws Exception {
System.out.println("testFinished "
+ description.toString());
}
public void testRunFinished(Result result) throws Exception {
System.out.println("testRunFinished " + result.toString()
+ " time:"+result.getRunTime()
+" R"+result.getRunCount()
+" F"+result.getFailureCount()
+" I"+result.getIgnoreCount()
);
}
}
在pom.xml中
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<!-- -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<properties>
<property>
<name>listener</name>
<value>com.example.mavenproject.PrintOutCurrentTestRunListener</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
</build>
朱尼特
朱尼特
4.12
测试
org.apache.maven.plugins
maven surefire插件
2.19.1
听众
com.example.mavenproject.PrintOutCurrentTestRunListener
或者,您可以在调试模式下运行maven,使用--debug
或-X
标志可能的重复项不会显示为System.out.println
进入maven控制台日志或任何报告。相反,为什么不从测试代码本身记录测试名称?