【问题标题】:Does Mule FunctionalTestCase needs org.junit.rules.TestRule class to runMule FunctionalTestCase 是否需要 org.junit.rules.TestRule 类才能运行
【发布时间】:2013-01-31 21:35:46
【问题描述】:

我正在尝试在 Mule 3.3 中运行一个简单的 Functional test。以下是我的示例代码:

import java.util.Map;    
import org.junit.Test;
import org.mule.api.MuleMessage;
import org.mule.api.client.MuleClient;
import org.mule.tck.junit4.FunctionalTestCase;
import static org.junit.Assert.*;

public class SoapServiceTest extends FunctionalTestCase {

    @Override
    protected String getConfigResources() {
        return "mule-config.xml,core-config.xml";
    }       

    @Test
    public void testSend() throws Exception
    {
        MuleClient client = muleContext.getClient();
        String payload = "foo";
        Map<String, Object> properties = null;
        MuleMessage result = client.send("http://localhost:61005/service", payload, properties);
        assertNotNull(result.getPayloadAsString());
    }    
}

但它抱怨java.lang.NoClassDefFoundError: org/junit/rules/TestRule。我的类路径中有junit4.8.1.jar,但没有TestRule 类,猜测是junit4.9 向前。

Mule 需要这个类吗?我没有使用TestRule的任何注释

【问题讨论】:

    标签: java junit junit4 mule junit-rule


    【解决方案1】:

    来自Mule's parent POM

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.9</version>
    </dependency>
    

    所以是的,Mule 依赖于 JUnit 4.9,无论你是否直接依赖它。

    添加时:

    <dependency>
        <groupId>org.mule.tests</groupId>
        <artifactId>mule-tests-functional</artifactId>
        <version>3.3.1</version>
        <scope>test</scope>
    </dependency>
    

    对于您项目的 POM,应该为您引入 JUnit 4.9。

    【讨论】:

    • 感谢 David 的回复和 pom 链接。我的项目正在使用Mule 3.3.0,我的项目 pom 中有上述依赖项,但也为junit4.8.1 定义了单独的依赖项。为什么 mule 可以拉起来的时候还需要为 junit 定义单独的依赖。我在这个样本pom 中看到了相同的趋势,尽管这定义了junit4.9
    • 如果添加mule-tests-functional,则不需要在POM中添加JUnit。在您指向的第 1 章的 POM 中添加它是我们的疏忽。我已经删除了。
    • 感谢您的清晰解释。希望我能多次投票
    猜你喜欢
    • 2019-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多