Search code examples
spring-bootspring-cloudspring-boot-test

Integration tests in spring boot application with spring cloud


I have an spring-boot application that uses config server. In project I have a bootstrap.yml:

spring:
 cloud:
    config:
      uri: ${CLOUD_CONFIG_URI:http://localhost:8888}
      failFast: true
      enabled: ??

and I can pass actual config for server location through parameter. That's ok.

With this configuration I don't know how to disable this in integration tests. My tests load this configuration and want to communicate with config server. I know that I can pass spring.cloud.config.enabled=false but it's not a solution (I want to right click in IDE and run test without additional configuration per each test method).

Any idea?


Solution

  • This is a late answer but for the people that join from any search engines here is my solution:

    The @Profile("test") annotation above your integration test class is correct. To get this really working is adding two extra configuration files to your normal resources folder, not the test resources folder.

    1. Add "application-test.yml"
    2. Add "bootstrap-test.yml"

    In your bootstrap-test.yml add the following:

    spring:
        cloud:
            config:
              enabled: false
    

    With this configuration you can put all of your needed configuration options in the application-test.yml and the bootstrap-test.yml will disabled spring cloud config.