Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 343
Bat Avatar asked Jan 18 '26 06:01

Bat


1 Answers

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.

like image 73
Bat Avatar answered Jan 19 '26 18:01

Bat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!