Closed BalasubramanyamEvani closed 3 years ago
I'm afraid there's no way to do that using JUnit 4's listener. You can, however, capture the output using a TestExecutionListener
when running the tests on the JUnit Platform (a.k.a. JUnit 5) with the JUnit Vintage Engine:
https://junit.org/junit5/docs/current/user-guide/#running-tests-capturing-output
https://junit.org/junit5/docs/current/user-guide/#launcher-api-listeners-custom
@BalasubramanyamEvani actually you may be able to capture the log messages JUnit 4. If your tests run serially, then you could update System.out
and/or System.err
in testStarted()
to point to a buffer or temporary file (whether this works depends on how your logging is done and how it is initialized). You won't know whether you are capturing logs of a passing or failing test util you receive testFailure()
or testFinished()
.
If tests can run in parallel then capturing the output of a single test can be challenging (especially if the tests can start threads). I personally think it's simpler to just capture the output of the test run, and possibly print out the test method name in testStarted()
.
You can get full test lifecycle notifications for parameterized JUnit 4 tests, including access to the parameter values, via the JUnit Foundation library.
Log messages are a bit more involved, but SLF4J includes support for something they call "mapped diagnostic context" that may be of assistance.
I'm creating a custom listener to update/send details to another application after a run. As I understand the following methods can be overridden for recording various test events.
testRunStarted, testRunFinished, testStarted, testFinished, testFailure, testAssumptionFailure, testIgnored
For my case, with the help above methods I've managed to capture the respective events, but is there a way to
Thanks for your time !