我有一个Spring应用程序和一个这样的基础测试类:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextHierarchy({
@ContextConfiguration(name = "parent", locations = "/app-context.xml"),
@ContextConfiguration(name = "child", locations = "/employee-context.xml")
})
public class EmployeeTests{
//...
}
和儿童测试课
@ContextHierarchy(
@ContextConfiguration(name = "child", locations = "/manager-context.xml")
)
public class ManagerTests extends EmployeeTests{
}
但这似乎加载了employee-context.xml和manager-context.xml的配置 我希望employee-context.xml配置在ManagerTests中没有任何效果,但是要在从EmployeeTests创建子类的其他类中生效
答案 0 :(得分:0)
您可以保留EmployeeTests,并将此行添加到ManagerTests
@ContextHierarchy(
@ContextConfiguration(name = "child",
locations = "/manager-context.xml",
inheritLocations = false //add this line to your code
))
public class ManagerTests extends EmployeeTests{
}