Search code examples
javamaven-3maven-failsafe-plugin

How to get the full stacktrace of failed tests in failsafe?


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.


Solution

  • 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.