【问题标题】:Spring test - @ContextConfiguration exclude base class contextSpring 测试 - @ContextConfiguration 排除基类上下文
【发布时间】:2013-01-18 04:13:53
【问题描述】:

使用 spring 和 @ContextConfiguration 进行测试时 是否有排除某些基类上下文的选项? 例如

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

和扩展类

public class someClass extends Base{

现在我希望 someClass 使用 context1.xml 但不是 context2.xml。有没有办法排除它? 问题是:我的所有测试(300 个测试)都有一个基类。我希望他们中的 all 使用 context1,这是一个覆盖原始上下文的模拟上下文。只有 一个 类应该使用原始上下文来测试它(如果 Base 没有它在其位置{},它将使用原始上下文)。

【问题讨论】:

    标签: java spring testing junit


    【解决方案1】:

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

    不过,我建议您看看新的Spring 3 bean profiles

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

    可以在here 找到一篇关于使用 spring bean 配置文件进行单元/集成测试的好文章。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-26
      • 2022-01-12
      • 2011-08-12
      • 1970-01-01
      相关资源
      最近更新 更多