【发布时间】:2021-12-13 14:31:51
【问题描述】:
我们有一些集成测试(使用 spring 框架编写)由于 bean 初始化异常而失败,最终导致 Failed to load ApplicationContext 。根据我对 spring testing docs 的理解,ApplicationContext 的加载发生在类级别,所以我的疑问是 -
-
一旦在集成测试类运行期间
ApplicationContext因bean 初始化异常 而失败(即Failed to load ApplicationContext),ApplicationContext是否会尝试再次启动(最终将失败)该特定集成测试类中存在的每个单独的集成测试?- 询问上述情况是因为当 bean 发生故障时,我们看到与 postgres 的连接数量激增,似乎对于集成测试类中存在的每个集成测试(最终由于
Failed to load ApplicationContext而失败),spring 试图创建一个到 postgres 的新连接,并且在ApplicationContext失败之前不会破坏它。我们如何才能阻止这种情况,请提供一些建议。
- 询问上述情况是因为当 bean 发生故障时,我们看到与 postgres 的连接数量激增,似乎对于集成测试类中存在的每个集成测试(最终由于
-
另外,一旦我们得到
Failed to load ApplicationContext,有没有办法以编程方式完全自动终止所有集成测试的运行?如果是,请帮助如何实现它? 谢谢。
测试框架 - junit + Spring
更新:使用了提到的测试框架。
【问题讨论】:
标签: java spring spring-boot integration-testing spring-test