Make maven's surefire show stacktrace in console

我希望在控制台中看到单元测试的堆栈跟踪?

42762 次浏览

您可以使用以下命令在控制台上查看堆栈跟踪,而不是在 target/surefire-reports 文件夹中查看报告文件:

mvn -Dsurefire.useFile=false test

要扩展前面给出的答案,您还可以在 pom.xml中配置此行为:

..
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
<configuration>
<useFile>false</useFile>
</configuration>
</plugin>
..

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>

解决了这个问题。