Search code examples
spring-bootspring-cloudspring-cloud-stream

Enabling test configuration and overriding config in Spring Boot application


Currently I'm working in a project which interacts with PubSub but I want it to also work with TestSupportBinderAutoConfiguration (executing tests without going to Google to retrieve the credentials).

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

By default, all the AutoConfiguration classes related to Google are included within the exclude property in @SpringBootApplication

However I've noticed that if the parent application.properties properties has some of the properties that I want to override, the application classes are still instantiated with those instead of the overriden ones, meaning that I'm trying to use TestSupportBinder classes with PubSub ones.

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

Is there any workaround for this? So that the main classes are configured with the newly overriden properties instead of gathering configs from different places in tests and main?


Solution

  • Effectively you're describing integration (with google) vs. unit testing (without google). Typically we separate the two. For example we have a separate integration module https://github.com/spring-cloud/spring-cloud-stream/tree/master/spring-cloud-stream-integration-tests and also Rabbit and Kafka are themselves in the separate modules for it's own integration testing.