我在spring boot中运行集成测试,@ value总是从src / main / resources / application.properties中选择属性值。如果我正在运行整合测试,它需要从scr / test / resources / application.properties中读取值。
@ContextConfiguration(classes = {ServiceConfig.class})
@SpringBootTest()
@ActiveProfiles("test")
public class RequestServiceSTTest {
@Autowired
private RequestService irServ;
@Test(priority = 0, description = "Request By Id")
public void testCreateRequest() {
irServ.createInvestmentRequest(tempIr);
Assert.assertEquals(newIr.getType(), "Test");
}
}
答案 0 :(得分:0)
检查this
以下示例演示了如何从类路径声明属性文件。
@ContextConfiguration
@TestPropertySource("/test.properties")
public class MyIntegrationTests {
// class body...
}
测试属性源的优先级高于从中加载的源 操作系统的环境或Java系统属性 作为属性源由应用程序以声明方式通过 @PropertySource或以编程方式。因此,测试属性源可以 用于有选择地覆盖系统中定义的属性 申请财产来源。此外,内联属性有 优先级高于从资源位置加载的属性。