【发布时间】:2015-04-28 15:17:32
【问题描述】:
我正在尝试模拟一个从 redis 获取数据的服务。我已经在新的上下文文件 test-context.xml 中注入了 spring 上下文中的 bean 但我有其他上下文文件 A.xml,B.xml 引用test-context.xml中beanS中的方法。我在enter link description here中阅读了问题
它创建了一个 BaseTest 类,但是当我继承该类时,我的子类中的上下文文件首先被加载,而不是它应该首先加载基类的上下文文件,因为子类上下文中的 bean 依赖于基类上下文。
@ContextConfiguration(locations = { "/META-INF/spring/testContext.xml" })
public abstract class myBaseTest {
@Before
public void init() {
// custom initialization code for resources loaded by testContext.xml
}
@After
public void cleanup() {
// custom cleanup code for resources loaded by testContext.xml
}
}
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/META-INF/spring/A.xml",
"/META- INF/spring/B.xml" })
public class childTest extends myBaseTest { ... }
【问题讨论】:
-
这不是您问题的答案,但请查看这篇文章以了解为什么不使用继承来测试系统petrikainulainen.net/programming/unit-testing/…