There are two approaches.
## Load from `config/`
*(2022 update, tested against Spring Boot 2.6)*
Along with the approach below, you can also add config to `src/test/resources/config/application.yml`
```none
src/
├── main/
│ ├── java/
│ │ └── ...
│ └── resources/
│ └── application.yml <- default properties, always loaded
└── test/
├── java/
│ └── ...
└── resources/
└── config/
└── application.yml <- test properties, will override the defaults
```
[To see links please register here]
> Spring Boot will automatically find and load `application.properties` and `application.yaml` files from the following locations when your application starts:
>
> 1. From the classpath
> 1. The classpath root
> 2. The classpath `/config` package
> 2. From the current directory
> 1. The current directory
> 2. The `/config` subdirectory in the current directory
> 3. Immediate child directories of the `/config` subdirectory
>
> The list is ordered by precedence (with values from lower items overriding earlier ones). Documents from the loaded files are added as `PropertySources` to the Spring `Environment`.
### Manual import using `spring.config.import`
*(original answer from 2021, tested against Spring Boot 2.4)*
One solution is to have 3 properties files and to import
* `src/main/resources/application.yml` - contains the application's default props
* `src/test/resources/application.yml` - sets the profile to 'test', and imports properties from 'main'
* `src/test/resources/application-test.yml` - contains test-specific profiles, which will override 'main'
Here is the content of `src/test/resources/application.yml`:
```yml
# for testing, set default profile to 'test'
spring.profiles.active: "test"
# and import the 'main' properties
spring.config.import: file:src/main/resources/application.yml
```
For example, if `src/main/resources/application.yml` has the content
```yml
ip-address: "10.7.0.1"
username: admin
```
and `src/test/resources/application-test.yml` has
```yml
ip-address: "999.999.999.999"
run-integration-test: true
```
Then (assuming there are no other profiles)...
when running tests,
```
profiles=test
--
ip-address=999.999.999.999
username=admin
run-integration-test=true
```
and when running the application normally
```
profiles=none
--
ip-address=10.7.0.1
username=admin
run-integration-test <undefined>
```
---
Note: if `src/main/resources/application.yml` contains `spring.profiles.active: "dev"`, then this won't be overwritten by `src/test/resources/application-test.yml`