问题描述
当测试失败时,target/surefire-reports/TEST-<test-name>.xml中的MAVEN中的SureFire测试报告XML文件仅显示标准输出System.output或标准错误System.err
当我使用jdk java.util.logging.Logger时,所有记录显示在标准错误<system-err> tag中,但是当我使用log4j时,它不会显示.
使用log4j的记录通过fileappender和consoleappender正常工作.它在完整的控制台输出中显示,但没有在单个测试报告文件中显示.
- 我可以配置log4j以将其输出重定向到System.out,因此它在SureFire Rerports中显示?
- 我可以告诉SureFire还显示Log4J调试记录吗?
推荐答案
更新Surefire插件版本.
使用版本2.9使用consoleappender
时,log4j输出出现在<system-out>中其他推荐答案
-
选项一:
对于标准日志记录(System.out/System.err),您可以具有以下输出:
<plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.8.1</version> <configuration> <redirectTestOutputToFile>true</redirectTestOutputToFile> </configuration> </plugin>
这将生成每个测试的输出文件.
-
选项两个:
对于Log4J配置
问题描述
When a test fails in maven the surefire test report xml files in target/surefire-reports/TEST-<test-name>.xml only shows the Standard Output System.output or Standard Error System.err
When I use the jdk java.util.logging.Logger all the logging shows in the Standard Error <system-err> tag, but it does not show when I use log4j.
The logging with log4j is working fine through a FileAppender and a ConsoleAppender. It shows in the full console output, but not on the individual test report files.
- Can I configure log4j to redirect its output to System.out so it shows in surefire rerports?
- Can I tell surefire to also show the log4j debug logging?
推荐答案
Update the surefire plugin version.
Using version 2.9 the log4j output appears in <system-out> when using the ConsoleAppender
其他推荐答案
Option one:
For standard logging (System.out/System.err), you can have the following output:
<plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.8.1</version> <configuration> <redirectTestOutputToFile>true</redirectTestOutputToFile> </configuration> </plugin>
This will generate output files for each of the tests.
Option two:
For a log4j configuration you can create a custom log4j.xml / log4j.properties and simply place it under src/test/resources.