Can we use JUnit annotations when using mule's

2019-05-14 04:55发布

问题:

We are using org.mule.tck.FunctionalTestCase for test cases. Its an abstract JUnit test case.

This is how the dependencies are declared in the pom.xml:

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

This is what the test code looks like:

import org.junit.Before;
import org.mule.tck.FunctionalTestCase;

public class SomeSuiteTest extends FunctionalTestCase {

    protected String getConfigResources() {
        return "my-mule-config.xml";
    }

    @Before
    public void doStuff() {
        ...
    }

    public void testThisCode() throws Exception {
        ...
    }
}

The problem is that doStuff() is never called. My understanding is that the method annotated by @Before is called before every test. Additionally, the @Test annotation is not part of the plug-in. It appears that I need to import that from org.junit as well, but I am not convinced it is supported.

Can we use JUnit annotations when using org.mule.tck.FunctionalTestCase?

--- Update ---

I found that a parent class of FunctionalTestCase, AbstractMuleTestCase, has a method titled doSetUp() that I can override in my test. Like an @Before method, it is called before every test. I would still prefer annotations since doSetUp() is not outlined in the JUnit documentation.

回答1:

If you extend the org.mule.tck.FunctionalTestCase class, you have to play by its rules, ie. override doSetUp(). Note that doSetUp() is not outlined in the JUnit documentation because it is specific to FunctionalTestCase.

Otherwise, extend org.mule.tck.junit4.FunctionalTestCase, which is Junit4-friendly.



标签: junit mule