I have a JUnit integration test that fails throwing an exception when executed by the Maven Failsafe plugin. I configured failsafe to write system out to a test-specific file (redirectTestOutputToFile=true). But neither that file nor the XML test result file contains the full stack trace of the exception. As in most cases, the interesting stuff is at the end of the caused-by chain.
Is there a possibility to configure failsafe in a way that records the full stacktrace somewhere?
Of course it would be possible to surround the test itself with a try-catch and log the stack trace manually, but this would lead to a lot of boilerplate code.
Please note: This question does NOT refer to surefire, but to failsafe and has been tagged accordingly. It does not ask of how to show the stacktrace in the console but how to make failsafe save the full stacktrace to a file and not only part of it. This answer is helpful, because it names the correct property, nonetheless it is not exactly correct, because of course the configuration must be applied to failsafe, not to surefire. Moreover, the accepted answer of question 2928548 is definitively wrong for this question.
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging.
During development, you may re-run failing tests because they are flaky. To use this feature through Maven surefire, set the rerunFailingTestsCount property to be a value larger than 0. Tests will be run until they pass or the number of reruns has been exhausted.
maven-surefire-plugin is designed for running unit tests and if any of the tests fail then it will fail the build immediately. maven-failsafe-plugin is designed for running integration tests, and decouples failing the build if there are test failures from actually running the tests.
failsafe:integration-test runs the integration tests of an application. failsafe:verify verifies that the integration tests of an application passed.
The failsafe configuration property trimStackTrace (which sadly is set to true by default) is responsible for the stacktrace manipulation (Thanks to Laf!). With the following it is deactivated:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
<!-- (...) -->
</plugins>
</build>
The output of the test itself can be redirected to a file with redirectTestOutputToFile, but this is not related to the stacktrace issue, because the stacktrace is an output of failsafe and not of the test code itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With