[英]Override application.properties for integration tests in spring-boot app
[英]Override default Spring-Boot application.properties with application.properties
想要用我的junit的application-test.properties
完全替换我的application.properties。 TestPropertySource
没有完成这项工作。 似乎它仅替换了一些常用属性,但我不希望这样。
要在我的Junit \\ application.properties
测试中加载application-test.properties
而不是application.properties
。
@RunWith(SpringRunner.class)
@ActiveProfiles( "test" )
@SpringBootTest(classes = Application.class)
@TestPropertySource(locations="classpath:application-test.properties")
@AutoConfigureMockMvc
该注释有一个可以抑制属性继承的属性:
@TestPropertySource(locations="classpath:application-test.properties", inheritProperties=false)
默认值为true
因此您需要显式设置。
根据文档:
如果InheritProperties设置为false,则测试类的内联属性将隐藏并有效替换超类定义的所有内联属性。
我通常在我的测试文件夹(src / test / resources)中有一个resources文件夹,我在其中放置了一个修改过的application.properties,而spring-boot应该使用这个文件夹。 参见https://www.baeldung.com/properties-with-spring 5.3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.