【问题标题】:Enabling test configuration and overriding config in Spring Boot application在 Spring Boot 应用程序中启用测试配置和覆盖配置
【发布时间】:2019-12-07 12:50:17
【问题描述】:

目前我正在一个与 PubSub 交互的项目中工作,但我希望它也可以与 TestSupportBinderAutoConfiguration 一起使用(执行测试而不去 Google 检索凭据)。

spring.profiles.active= pubsub

spring.main.web-application-type=none
spring.cloud.stream.default-binder=test

spring.cloud.stream.bindings.output.destination= output-queue
spring.cloud.stream.bindings.input.destination= input-queue

默认情况下,与 Google 相关的所有 AutoConfiguration 类都包含在 @SpringBootApplicationexclude 属性中

但是我注意到,如果父 application.properties 属性有一些我想要覆盖的属性,应用程序类仍然使用那些而不是被覆盖的属性来实例化,这意味着我正在尝试使用 TestSupportBinder带有 PubSub 的类。

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = MyProcessor.class, webEnvironment = SpringBootTest.WebEnvironment.NONE)
@TestPropertySource(properties = {
    "--spring.profiles.active="
})

有什么解决方法吗?这样主类就配置了新覆盖的属性,而不是从测试和主类的不同位置收集配置?

【问题讨论】:

    标签: spring-boot spring-cloud spring-cloud-stream


    【解决方案1】:

    实际上,您是在描述集成(使用 google)与单元测试(没有 google)。通常我们将两者分开。例如,我们有一个单独的集成模块https://github.com/spring-cloud/spring-cloud-stream/tree/master/spring-cloud-stream-integration-tests,并且 Rabbit 和 Kafka 本身也在单独的模块中,用于自己的集成测试。

    【讨论】:

    • 非常感谢奥列格的回复!因此,您会说有一个“通用”父模块来实现将使用给定配置部署的应用程序,然后创建单独的模块,这些模块依赖于父模块以及另一个 application.properties 和特定类,以便测试在内部开发是要走的路吗?
    • 类似的,是的
    猜你喜欢
    • 2017-12-13
    • 1970-01-01
    • 1970-01-01
    • 2018-12-25
    • 1970-01-01
    • 2016-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多