【问题标题】:Is it possible to enable Spring context caching in Mule FunctionalTestCase?是否可以在 Mule FunctionalTestCase 中启用 Spring 上下文缓存?
【发布时间】:2018-01-10 22:30:10
【问题描述】:

我使用 FunctionalTestCase 来测试 Mule ESB 3.5 应用程序。

为了测试,我有一个看起来像这样的类:

public class MyIntegrationTest extends FunctionalTestCase {

    @Override
    protected String getConfigFile()
    {
        return "app-config.xml";
    }

    @Test
    public void test1() throws Exception{
    }
    @Test
    public void test2() throws Exception{
    }
    ...
}

我注意到每个@Test 方法都会重新创建应用程序上下文并且测试相当慢。

使用裸 Spring 框架,简单的集成测试会缓存应用程序上下文,因此测试会快得多。我想知道是否可以使用缓存的 Spring 应用程序上下文进行 Mule 应用程序集成测试?

【问题讨论】:

    标签: spring mule


    【解决方案1】:

    AbstractMuleContextTestCase 具有 disposeContextPerClass 属性。您需要将其设置为 true 以实现每个测试类的上下文缓存。首先我浪费了一些时间试图在@Before 方法中设置它,但已经太晚了。

    我设法通过在测试类构造函数中使用disposeContextPerClass(true) 来启用上下文缓存:

    @RunWith(JUnit4.class)
    public class MyIntegrationTest extends FunctionalTestCase {
        public MyIntegrationTest() {
            setDisposeContextPerClass(true);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多