首页 > 解决方案 > Java:如何在 Spring Boot 测试中实现 @BeforeAll 和 @AfterAll?

问题描述

有没有其他方法可以在 junit5 中为 Spring Boot 应用程序使用 @BeforeAll 和 @AfterAll 逻辑?它看起来像 Spring Boot 只是忽略了这些注释。测试类以注释开头:

@ExtendWith(SpringExtension.class)
@SpringBootTest

我还尝试覆盖类 AbstractTestExecutionListener 的 beforeTestClass 和 afterTestClass 方法并添加注释:

@TestExecutionListeners(listeners = 
{DependencyInjectionTestExecutionListener.class, SearchManagerTest.class})

但 Spring Boot 也忽略了它。

标签: javaspring-bootjunit5

解决方案


推荐阅读