How to show log4j output in surefire test resports

房东的猫 提交于 2020-01-01 01:53:13

问题


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?

回答1:


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




回答2:


Update the surefire plugin version.

Using version 2.9 the log4j output appears in <system-out> when using the ConsoleAppender



来源:https://stackoverflow.com/questions/4379996/how-to-show-log4j-output-in-surefire-test-resports

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!