问题:
Want to completely replace my application.properties with application-test.properties for my junit. TestPropertySource is not doing the job. Seems like it only replaces som...
可以将文章内容翻译成中文,广告屏蔽插件会导致该功能失效:
问题:
Want to completely replace my application.properties with application-test.properties
for my junit. TestPropertySource
is not doing the job. Seems like it only replaces some of the common properties but i dont want that.
Want to load application-test.properties
not application.properties
in my Junit integraction test.
@RunWith(SpringRunner.class)
@ActiveProfiles( "test" )
@SpringBootTest(classes = Application.class)
@TestPropertySource(locations="classpath:application-test.properties")
@AutoConfigureMockMvc
回答1:
There is a property to that annotation that would suppress inheritance of properties:
@TestPropertySource(locations="classpath:application-test.properties", inheritProperties=false)
The default is true
so you need to set that explicitly.
As per documentation:
If inheritProperties is set to false, the inlined properties for the test class will shadow and effectively replace any inlined properties defined by a superclass.
回答2:
I normally have a resources folder in my test folder (src/test/resources) where i place a modified application.properties and spring-boot should take this. See on https://www.baeldung.com/properties-with-spring 5.3