How to run Maven surefire without printing out test results to the command line?

大兔子大兔子 提交于 2019-12-30 04:40:06

问题


I am running the Maven 3.1.0 Surefire plugin already with the --quiet option, however it still prints out the results of unit tests out to the command line, even if they all pass. Is there a way to only get it to print failures?

The output I'd like to suppress if everything is fine looks like:

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

No, I do not want to pipe the output to /dev/null


回答1:


Try setting the surefire.printSummary property to false: this should only print the test cases that have errors. So try running it as mvn -q -Dsurefire.printSummary=false.

Alternatively, you can put it in your pom.xml:

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


来源:https://stackoverflow.com/questions/18489112/how-to-run-maven-surefire-without-printing-out-test-results-to-the-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!