130

I'd like to see the stacktrace of unit tests in the console. Does surefire support this?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
IAdapter
  • 62,595
  • 73
  • 179
  • 242

3 Answers3

272

A related problem that I found is that surefire in recent versions apparently sets trimStackTrace to true by default (rendering most stack trace in failed tests useless), which is quite inconvenient.

Setting -DtrimStackTrace=false or defining

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

solved this.

howlger
  • 31,050
  • 11
  • 59
  • 99
h7r
  • 4,944
  • 2
  • 28
  • 31
  • 97
    Yep. Not only does Maven print pages of pointless diarrhea, but it hides what you actually need to see. – Sridhar Sarnobat Oct 05 '16 at 18:18
  • 9
    I created an issue about this wrong default https://issues.apache.org/jira/browse/SUREFIRE-1457. Please comment it to help its reopening. – Réda Housni Alaoui Jan 09 '18 at 10:29
  • 4
    @RédaHousniAlaoui Seems they moved it to another issue for JUnit 5: https://issues.apache.org/jira/browse/SUREFIRE-1432 Just voted there. – Kariem Dec 18 '18 at 10:45
  • 1
    I set both 'trinStackTrace' and 'useFile' to false... and still I'm just getting no stack traces for my test failures :-( – Kris Jun 17 '20 at 18:40
  • @Kris do you means stack traces has lots of line, the output show ... 26 more? – netawater Aug 14 '20 at 07:42
  • Default is now `trimStackTrace=false` in 3.0.0-M6. However, we're still using 3.0.0-M5 ... `:--)` – Charlie Reitzel Sep 14 '22 at 17:03
60

You can use the following command to see the stack trace on console instead of report files in the target/surefire-reports folder:

mvn -Dsurefire.useFile=false test
Eugene Kuleshov
  • 31,461
  • 5
  • 66
  • 67
29

To extend the answer given before, you also can configure this behavior in your pom.xml:

..
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.5</version>
  <configuration>
    <useFile>false</useFile>
  </configuration>
</plugin>
..
yegor256
  • 102,010
  • 123
  • 446
  • 597