Make maven's surefire show stacktrace in console
Asked Answered
C

3

131

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

Clam answered 28/5, 2010 at 11:31 Comment(0)
V
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
Viscosity answered 28/5, 2010 at 12:52 Comment(2)
This only have logger output into console, but stacktraces still goes to surefire-reportsKristalkristan
The answer using trimStackTrace is better!Uterus
D
276

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.

Dovetail answered 5/6, 2013 at 13:37 Comment(6)
Yep. Not only does Maven print pages of pointless diarrhea, but it hides what you actually need to see.Extreme
I created an issue about this wrong default issues.apache.org/jira/browse/SUREFIRE-1457. Please comment it to help its reopening.Berserk
@RédaHousniAlaoui Seems they moved it to another issue for JUnit 5: issues.apache.org/jira/browse/SUREFIRE-1432 Just voted there.Diaconal
I set both 'trinStackTrace' and 'useFile' to false... and still I'm just getting no stack traces for my test failures :-(Insane
@Insane do you means stack traces has lots of line, the output show ... 26 more?Anacreon
Default is now trimStackTrace=false in 3.0.0-M6. However, we're still using 3.0.0-M5 ... :--)Owlet
V
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
Viscosity answered 28/5, 2010 at 12:52 Comment(2)
This only have logger output into console, but stacktraces still goes to surefire-reportsKristalkristan
The answer using trimStackTrace is better!Uterus
P
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>
    ...
Preterition answered 21/7, 2010 at 16:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.