有沒有辦法讓maven surefire打印每個單元測試的名稱(即測試方法)它的開始?maven surefire:如何打印當前正在運行的測試?
喜歡的東西:
testFoo: ... passed
testBar: ... failed
有沒有辦法讓maven surefire打印每個單元測試的名稱(即測試方法)它的開始?maven surefire:如何打印當前正在運行的測試?
喜歡的東西:
testFoo: ... passed
testBar: ... failed
這是一個有點舒展的,但你可以實現一個RunListener,並把它添加到萬無一失。瞭解如何配置它here。
在細節
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>
不會像'System.out.println'這樣出現在Maven控制檯日誌中,也不會出現任何報告。 – ThaDon
可能複製http://stackoverflow.com/questions/15203756/maven-displaying-unit-test-currently-running的 –