【问题标题】:How to run code after test failure in JUnit5?在 JUnit5 中测试失败后如何运行代码? 【发布时间】:2019-06-20 06:37:03 【问题描述】: 在 JUnit 5 中测试失败后如何运行函数或总结代码? 【问题讨论】: 看TestWatcher stackoverflow.com/questions/49037406/testwatcher-in-junit5的可能重复 标签: java testing junit junit5 【解决方案1】: 这可以在 JUnit 5 中使用 TestWatcher 来完成。但是在 JUnit 4 上,您可以使用 ErrorCollector。 This answer 出色地为您的问题提供了解决方案。 【讨论】: