且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Spring Boot集成测试不会读取属性文件

更新时间:2022-04-10 23:58:11

您应该使用@PropertySource或@TestPropertySource加载application-test.properties

You should load the application-test.properties using @PropertySource or @TestPropertySource

@RunWith(SpringJUnit4ClassRunner.class)
@TestPropertySource(locations="classpath:application-test.properties")
@ContextConfiguration(classes = {WebTests.ConfigurationClass.class, WebTests.ClassToTest.class})
public class WebTests {

}

了解更多信息:查看覆盖Junit测试中的默认Spring-Boot application.properties设置