11

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.

Community
  • 1
  • 1
Gustave
  • 3,359
  • 4
  • 31
  • 64
  • 1
    See answer [here](http://stackoverflow.com/a/16941432/994125) to the dupe question above. – Laf Feb 22 '17 at 13:38
  • It should be obvious that this question is not at least an "exact" duplicate ("This question was marked as an exact duplicate of an existing question."). Surefire and Failsafe are treated independant plugins by Maven and the relevant documentation, even if they share a lot of code. – Gustave Feb 28 '17 at 15:12
  • I would share the answer I found here, but this is not possible because the question has to be reopened before. This is somewhat frustrating. Please think twice and read carefully before marking a question as duplicate. – Gustave Feb 28 '17 at 15:57
  • Sorry, I read your question and the duplicate candidate, and misread your question. – Laf Feb 28 '17 at 16:38

1 Answers1

21

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.

Gustave
  • 3,359
  • 4
  • 31
  • 64
  • It shows a lot of configuration there. The answer is correct, but does not point you exactly which line you nee. – Jhovanni Apr 18 '19 at 13:57
  • I tried to make trimStackTrace bold, but that seems impossible in a code section. I don't know if its possible to add line numbers. – Gustave Jul 10 '19 at 16:54
  • 1
    It appears to work fine to add `false` to the `` block under the root ``. This would presumably affect surefire as well, but I would see that as a bonus. – meustrus Oct 17 '19 at 14:57
  • 1
    Following the comment of @meustrus, you can even pass it as a command-line parameter: `-DtrimStackTrace=false` – Didier L Aug 02 '21 at 14:20