如何在不将测试结果打印到命令行的情况下运行Maven surefire?

时间:2013-08-28 13:17:47

标签: maven maven-surefire-plugin

我正在使用--quiet选项运行Maven 3.1.0 Surefire plugin 已经,但它仍会将单元测试的结果输出到命令行,甚至如果它们都通过了。 有没有办法只让它打印失败?

如果一切都很好,我想要抑制的输出看起来像:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running net.initech.project.dawgs.actionfactory.InterfaceActionFactoryTest
Tests run: 14, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.425 sec
Running net.initech.project.dawgs.actionfactory.ValueScopeTest
Tests run: 8, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec
Running net.initech.project.dawgs.assertion.AssertContainsTest
Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.011 sec
Running net.initech.project.assertion.AssertEndsWithTest
Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.012 sec
Running net.initech.project.assertion.AssertIsEqualTest
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.006 sec
Running net.initech.project.assertion.AssertIsLikeTest
Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.012 sec
Running net.initech.project.assertion.AssertStartsWithTest
Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.008 sec

Results :

Tests run: 52, Failures: 0, Errors: 0, Skipped: 0

不,我不想将输出传递给/dev/null

1 个答案:

答案 0 :(得分:6)

尝试将surefire.printSummary属性设置为falsethis should only print the test cases that have errors.因此请尝试将其mvn -q -Dsurefire.printSummary=false运行。

或者,您可以将它放在pom.xml中:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>            
      <printSummary>false</printSummary> 
    </configuration>
  </plugin>