Maven Surefire records standard output and error output for every failed tests which can be later found in generated files in surefire-reports
directory. The output of tests which pass with no error is however discarded. Is it possible to set up surefire to record the stdout/stderr also for tests which successfully pass?
Asked
Active
Viewed 3,781 times
6

Hynek
- 61
- 1
- 2
1 Answers
6
Yes. You can redirect the output of your tests to a file with this optional parameter:
It's defaulted to false. If you switch it on with:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
</configuration>
</plugin>
Your unit test output will be written to reportsDirectory/testName-output.txt

serg10
- 31,923
- 16
- 73
- 94
-
Thanks, that one I have tried already - it however does not work for me - the output in testName-output.txt is empty after test terminates. I can see the output file growing and containing the output while test is running, however after the test case execution terminates, the file is truncated down to 0 bytes and the output is lost. Any thoughts? – Hynek Mar 03 '14 at 09:53
-
That's a little odd. Is anything else overwriting that property setting? Do you see any errors if you run with verbose output switching on? Do you have the "useFile" property switched off by any chance? – serg10 Mar 03 '14 at 13:57
-
it does not work for me, intellij complain with element not allowed here – J. Doem May 13 '17 at 11:36