By default in a unit test class annotated with @SpringBootTest
, a properties file in /src/main/java/resources
is ignored if one exists in /src/test/java/resources
.
How do you construct a test that loads values from both?
For example, this test will pass:
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
class PortTests {
@Test
void testDefaultPort(@LocalServerPort int port) {
assertThat(port).isEqualTo(12345);
}
}
If the following file exists:
/src/main/java/resources/application.yaml
server:
port: 12345
But that same test fails if you add the following file as well:
/src/test/java/resources/application.yaml
:
foo: bar
How do you construct a test that passes when both files exist?