【发布时间】:2016-01-27 02:16:10
【问题描述】:
我正在为我的 Spring Boot 应用程序编写集成测试,但是当我尝试使用 @TestPropertySource 覆盖某些属性时,它会加载上下文 xml 中定义的属性文件,但它不会覆盖注释中定义的属性。
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = {DefaultApp.class, MessageITCase.Config.class})
@WebAppConfiguration
@TestPropertySource(properties = {"spring.profiles.active=hornetq", "test.url=http://www.test.com/",
"test.api.key=343krqmekrfdaskfnajk"})
public class MessageITCase {
@Value("${test.url}")
private String testUrl;
@Value("${test.api.key}")
private String testApiKey;
@Test
public void testUrl() throws Exception {
System.out.println("Loaded test url:" + testUrl);
}
@Configuration
@ImportResource("classpath:/META-INF/spring/test-context.xml")
public static class Config {
}
}
【问题讨论】:
-
您解决了这个问题吗?通过 TestPropertySource 的内联属性似乎也不适合我。
-
还没有,但是我已经更改了我的配置,以便我使用
@IntegrationTest注释而不是@TestPropertySource。我会尽快发布答案。
标签: spring spring-boot integration-testing spring-test