【发布时间】:2014-01-20 15:25:45
【问题描述】:
是否有可能为一个或多个集成测试替换 Spring 配置中的单个 bean 或值?
就我而言,我有配置
@Configuration
@EnableAutoConfiguration
@ComponentScan(basePackages = {"foo.bar"})
public class MyIntegrationTestConfig {
// everything done by component scan
}
用于我的集成测试
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = MyIntegrationTestConfig.class, loader = SpringApplicationContextLoader.class)
public class MyIntegrationTest {
// do the tests
}
现在我想要进行第二组集成测试,用不同的 bean 替换一个 bean。
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = MyIntegrationTestConfig.class, loader = SpringApplicationContextLoader.class)
public class MySpecialIntegrationTest {
// influence the context configuration such that a bean different from the primary is loaded
// do the tests using the 'overwritten' bean
}
实现这一目标的最简单方法是什么?
【问题讨论】:
标签: spring configuration config