1

My test properties are overriden with those placed in production properties. At the very beggining I had both named application.yml but it didn't work, so I have changed like told in this post to application-test.yml and use profile. Now it looks like bellow (kotlin):

@SpringBootTest
@ExtendWith(SpringExtension::class)
@ContextConfiguration(classes = [InvalidPropertiesApplication::class])
@ActiveProfiles("test")
@TestPropertySource(locations = ["classpath:application.yml"])
class InvalidPropertiesApplicationTests {
    @Test
    fun contextLoads(@Autowired users: Users) {
        assertEquals("TEST", users.file)
    }
}

in src/main/resources/application.yml I have only set this property to PRODUCTION, in src/test/resources/application-test.yml to TEST.

And this test fails. Full example can be found at github

Thx in advance.

Witold Kupś
  • 524
  • 7
  • 14

1 Answers1

2

Properties loaded with @TestPropertySource have a higher precedence than all other property sources in your example. And "classpath:application.yml" refers to src/main/resources/application.yml.

Order: @TestPropertySource > application-{profile}.properties/yaml > application.properties/yaml

See also the Spring Boot Reference Guide.

Roland Weisleder
  • 9,668
  • 7
  • 37
  • 59
  • Thx, I have seen this and made some changes, but no dif... However, now it helped, maybe cache or smth. – Witold Kupś Oct 16 '18 at 08:05
  • But if I had specified `@TestPropertySource(locations = ["classpath:application.yml"])` and both property files were named `application.yml`, shouldn't the one from `test` be resolved? – Witold Kupś Oct 16 '18 at 10:00