Section 4.7 of the JUnit user manual (https://junit.org/junit5/docs/current/user-guide/#running-tests-capturing-output) talks about capturing standard output/error using listeners, and the following section says that the API already contains a class called LoggingListener
. I can create one using:
LoggingListener listener = LoggingListener.forJavaUtilLogging(Level.INFO);
but I'm not sure how to proceed after that. I want to capture the log output happening at INFO level. I already added
junit.platform.output.capture.stdout=true
junit.platform.output.capture.stderr=true
to junit-platform.properties
under src/test/resources
, as it says to do. The listener class contains a method called reportingEntryPublished
which takes a TestIdentifier
and a ReportEntry
, but I'm not sure how to use that, assuming that's even the right method to call.
Any advice would be appreciated. The User Manual section makes it sound easy, but I can't find any examples anywhere (including in the tests of the source code on GitHub).
BTW, suggestions from both ChatGPT and Bard are hilarious.