Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 427
Gustave Avatar asked Feb 15 '17 12:02

Gustave


People also ask

How do you see the full stack trace of the errors re-run Maven with the switch?

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

How do I run only failed test cases in Maven?

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.

What is the difference between Maven Surefire and Maven failsafe plugins?

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.

What is failsafe test?

failsafe:integration-test runs the integration tests of an application. failsafe:verify verifies that the integration tests of an application passed.


1 Answers

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.

like image 179
Gustave Avatar answered Oct 13 '22 01:10

Gustave