当前位置: 首页 > 文档资料 > JUnit 5 用户指南 >

1.2.4.7. Capturing Standard Output/Error

优质
小牛编辑
137浏览
2023-12-01

Since version 1.3, the JUnit Platform provides opt-in support for capturing output printed to System.out and System.err. To enable it, simply set the junit.platform.output.capture.stdout and/or junit.platform.output.capture.stderr configuration parameter to true. In addition, you may configure the maximum number of buffered bytes to be used per executed test or container using junit.platform.output.capture.maxBuffer.

If enabled, the JUnit Platform captures the corresponding output and publishes it as a report entry using the stdout or stderr keys to all registered TestExecutionListener instances immediately before reporting the test or container as finished.

Please note that the captured output will only contain output emitted by the thread that was used to execute a container or test. Any output by other threads will be omitted because particularly when executing tests in parallel it would be impossible to attribute it to a specific test or container.

Capturing output is currently an experimental feature. You’re invited to give it a try and provide feedback to the JUnit team so they can improve and eventually promote this feature.