Wick Technology Blog

Micronaut Test Configuration

December 28, 2019

When configuring the test of a Spring Boot application, you may be used to using an application properties file e.g. application.yaml in src/test/resources with the same name as the main configuration file in src/main/resources. This will merge the properties from the test application config file with the properties from the main config.

If you use the same approach in Micronaut, naming the config file in src/test/resources with the same name and your config file in src/main/resources, you’ll find that the whole main configuration will be overridden with the test configuration.

This is usually not what you want. It’s usually preferable to just override the properties we want for a test and leave all the other properties as configured in the main config. To do this in Micronaut, use environment-specific property files. When you annotate a test with @MicronautTest it automatically adds the “test” environment. So create a file called application-test.yaml in src/test/resources and you can just override those properties you need for your test, not the entire main config.

Phil Hardwick

Written by Phil Hardwick