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

1

9

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

Fluff answered 28/8, 2013 at 13:17 Comment(1)
Glad someone asked this. I wish maven defaults didn't produce this diarrhea.Roumell
T
8

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>
Tajo answered 28/8, 2013 at 13:33 Comment(4)
This still prints the "----<br>TESTS----<br>" banner, any idea how to get rid of that? I'm tempted to file that as a feature request against SureFire since it seems it ought to be included in that option.Fluff
One more caveat that fooled me: if your command has -Dsurefire.useFile=false, then the setting of -Dsurefire.printSummary=false will not be respected.Roumell
Another caveat - inside a pluginManagement element this setting seems to get ignored.Roumell
And another caveat - if you have printSummary=false, then <trimStackTrace>false</trimStackTrace> will not be respectedEvergreen

© 2022 - 2024 — McMap. All rights reserved.