I'd like to see the stacktrace of unit tests in the console. Does surefire support this?
Asked
Active
Viewed 4.6k times
3 Answers
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.
-
97Yep. 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
-
9I 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
-
1I 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
-
2This only have logger output into console, but stacktraces still goes to surefire-reports – lisak May 24 '11 at 23:01
-
10
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