Spring测试 - @ContextConfiguration排除基类上下文。

3

在使用Spring和@ContextConfiguration进行测试时,是否有一种选择可以排除某些基类上下文呢?例如:

@ContextConfiguration(locations = {"context1.xml", "context2.xml"})
public class Base{

并扩展类

public class someClass extends Base{

现在我想让someClass使用context1.xml而不是context2.xml。有没有一种方法可以把它排除在外?

问题是:我有一个基类用于所有我的测试(300个测试)。我希望所有的测试都使用mock上下文覆盖原始上下文的context1。只有一个类应该使用原始上下文进行测试(如果基类的locations{}中没有它,它将使用原始上下文)。

1个回答

3

如前所述,排除上下文将不可能。

但是,我建议您查看新的Spring 3 bean profiles

通过指定/激活正确的配置文件,您应该能够以更干净的方式实现相同的功能...

有关使用Spring Bean配置文件进行单元/集成测试的好文章可以在此处找到。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接