2015-06-01 2 views
1

Есть ли способ получить maven surefire для печати имени каждого модульного теста (т. Е. Метода тестирования), который он запускает?maven surefire: как распечатать текущий тест?

Что-то вроде:

testFoo: ... passed 
testBar: ... failed 
+0

Возможно дубликата http://stackoverflow.com/questions/15203756/maven-displaying-unit-test-currently-running –

ответ

2

Это немного растянуть, но вы могли бы реализовать RunListener и добавить его в безошибочный. Посмотрите, как его настроить. here.

2

В деталях

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> 
+0

Не похоже, что 'System.out.println' делает его в журнале консоли Maven, ни в отчете. – ThaDon

Смежные вопросы