有没有办法让maven肯定能够打印它开始的每个单元测试的名称(即测试方法)?
类似的东西:
testFoo: ... passed
testBar: ... failed
答案 0 :(得分:3)
详情
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>
答案 1 :(得分:2)
它有点伸展,但您可以实现RunListener并将其添加到surefire。了解如何配置here。
答案 2 :(得分:0)
或者,您可以使用--debug
或-X
标志在调试模式下运行maven