Skip to content
Advertisement

Micronaut test in docker overriding the MICRONAUT_ENVIRONMENTS

We run our micronaut integration tests in the cloud in a docker container

We’re setting the MICRONAUT_ENVIRONMENTS=staging in the docker environment variables, to force our application to read the config values from application-staging.yaml.

However, micronaut is automatically adding “test” as an environment, and then read the config values from application-test.yaml.

From the docs (https://docs.micronaut.io/2.2.1/guide/index.html#propertySource), environment variables should have priority compared to deduced environments when loading the config

Is there any reason why micronaut is giving priority to the application-test.yaml values here?

Advertisement

Answer

The test environment is added when micronaut tests are running, even when setting up the environment variable MICRONAUT_ENVIRONMENTS

After a bit of digging, it seems the “test” environment is added before the DefaultEnvironment class is initialized, hence it’s added even if micronaut.env.deduction is set to false

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement