【问题标题】:How to count the number of times the spring boot loads on spring tests?如何计算弹簧测试中弹簧靴加载的次数?
【发布时间】:2020-06-28 10:28:04
【问题描述】:

我有一个带有弹簧启动测试的应用, 我可以强制加载弹簧引导的次数吗? 所以如果有人要加载另一个弹簧靴,我会发出警告。

【问题讨论】:

  • Spring 测试上下文已经缓存并重用了加载的上下文,为什么要限制呢?如果已加载配置不同,或者您正在手动加载它并围绕测试上下文框架工作。所以看起来你正在尝试解决错误的问题。
  • 在我的应用程序中加载 spring boot 大约需要 10 秒。我想节省时间,从而减少构建时间。
  • 应该已经加载过一次了!如果不是这种情况,您在测试中做错了什么,或者由于配置、测试执行侦听器的差异或由于@DirtiesContext(列举最常见的那些)而实际需要它。

标签: java spring spring-boot testing integration-testing


【解决方案1】:

这个问题有点笼统,我的回答可能不是我们想要的。

logging.level.org.springframework.test.context.cache: debug 您可以监控加载了多少上下文,例如这个项目使用 7 个上下文:

Spring测试ApplicationContext缓存统计:[DefaultContextCache@3655a68c size = 7, maxSize = 32, parentContextCount = 0, hitCount = 1780, missCount = 7]

【讨论】:

    猜你喜欢
    • 2017-12-22
    • 2019-05-03
    • 2018-10-03
    • 2018-02-14
    • 2021-04-20
    • 1970-01-01
    • 2023-01-07
    • 2018-07-10
    • 1970-01-01
    相关资源
    最近更新 更多