如何在模块中执行所有junit5测试之前和之后编写一次代码?

如何在模块中执行所有junit5测试之前和之后编写一次代码?

问题描述:

我有一个多模块项目spring boot项目,其中每个模块都产生一个jar.每个模块都有一个带有junit 5测试的src/main/test.在特定模块中的src/main/test中的所有测试执行之前和之后,是否可以运行代码?例如,如果我有2个模块A和B,我想要.

I have a multi module project spring boot project, where each module produces a jar. Each module has a src/main/test with junit 5 tests. Is there a way to run code before and after all the tests in src/main/test in a specific module execute? For example if I have 2 modules A, and B I want.

  • 在模块A中的所有测试执行之前运行代码
  • 运行所有测试模块A执行的代码
  • 在模块B中的所有测试执行之前运行代码
  • 在模块B中的所有测试执行后运行代码

您可以定义测试类中方法的顺序,但不能定义测试类的顺序.

You can define the order for methods in a test class, but not for order of test classes.

对此功能有一个公开的请求,但是尚无消息说JUnit将实现它:

There is an open request for this feature, but there's no word yet if JUnit will implement it: https://github.com/junit-team/junit5/issues/1948