java - 如果发生 `Failed to load ApplicationContext` 错误,自动终止所有集成测试
问题描述
我们有一些集成测试(使用 spring 框架编写)由于bean 初始化异常而失败,最终导致Failed to load ApplicationContext
. 根据我对spring testing docs的理解,加载ApplicationContext
发生在类级别,所以我的疑问是 -
一旦在集成测试类运行期间由于bean 初始化异常
ApplicationContext
而 失败(即),是否 会为该特定集成测试类中存在的每个单独的集成测试再次尝试启动(最终将失败)?Failed to load ApplicationContext
ApplicationContext
- 询问上述情况是因为当 bean 发生故障时我们看到与 postgres 的连接数量激增,似乎对于集成测试类中存在的每个集成测试(最终由于 失败
Failed to load ApplicationContext
),spring 尝试创建与 postgres 的新连接并且在失败之前不会破坏它ApplicationContext
。我们如何才能阻止这种情况,请提供一些建议。
- 询问上述情况是因为当 bean 发生故障时我们看到与 postgres 的连接数量激增,似乎对于集成测试类中存在的每个集成测试(最终由于 失败
此外,一旦我们得到
Failed to load ApplicationContext
,有没有办法以编程方式完全自动终止所有集成测试的运行?如果是,请帮助如何实现它?谢谢。
测试框架——junit + Spring
更新:使用了提到的测试框架。
解决方案
如果ApplicationContext
反复加载失败,目前无法中止集成测试。
要投票支持此类支持,请参阅此 Spring Framework 问题。
推荐阅读
- javascript - 如何以编程方式破坏剑道网格?
- c# - 尽管 EditText 的 InputType 是 ClassText,但允许文本输入
- c# - 如何获取当前的测试夹具属性
- reactjs - React MaterialUI v3.7 知道在输入下会出现帮助文本,如何设置高度?
- javascript - 当我使用 .value 获取输入值时,它返回 Undefined
- java - 为任何双精度生成本地化、全精度输出的 MessageFormat 模式是什么
- xamarin - 北欧Dfu库的Xamarin绑定
- c++ - Cpp,强制执行预处理器评估顺序
- sql - 如何使用数据工厂从表缓存中删除数据?
- python - 为什么我会在 'where 子句' 中得到“未知列 'Jacob'”?