Search code examples
javatestingjunitjunit5

How to run code after test failure in JUnit5?


How can I run a function or a wrap-up code after a test failed in JUnit 5?


Solution

  • This can be done using TestWatcher in JUnit 5. On JUnit 4 however, you can use ErrorCollector.

    This answer brilliantly provides a solution to the problem.