Search code examples
javajboss-arquillianjmockit

Arquillian org.junit.runner.Runner NoClassDefFoundError when JMockit on classpath


I am attempting to do a really simple Arquillian test against a remote Weblogic 12.1.x so for example I have the following

public class MyBean {

}

And then the test

@RunWith(Arquillian.class)
public class InjectionTest {

    @Deployment
    public static JavaArchive createDeployment() {
        return ShrinkWrap.create(JavaArchive.class, "lib.jar")
            .addClass(MyBean.class)
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
     }

    @Inject
    MyBean bean;

    @Test
    public void test_bean_not_null() {
        Assert.assertNotNull(bean);
    }

}

Simple enough! However I get the following stack trace

java.lang.NoClassDefFoundError: org.junit.runner.Runner
                at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:61)
                at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
                at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:36)
                at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
                at org.jboss.arquillian.junit.container.JUnitTestRunner.execute(JUnitTestRunner.java:66)
                at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.executeTest(ServletTestRunner.java:170)
                at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.execute(ServletTestRunner.java:135)
                at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.doGet(ServletTestRunner.java:98)
                at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
                at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
                at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:286)
                at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:260)
                at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:137)
                at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:350)
                at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25)
                at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78)
                at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:32)
                at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78)
                at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3683)
                at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3649)
                at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:326)
                at weblogic.security.service.SecurityManager.runAsForUserCode(SecurityManager.java:197)
                at weblogic.servlet.provider.WlsSecurityProvider.runAsForUserCode(WlsSecurityProvider.java:203)
                at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:71)
                at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2433)
                at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2281)
                at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2259)
                at weblogic.servlet.internal.ServletRequestImpl.runInternal(ServletRequestImpl.java:1691)
                at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1651)
                at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:270)
                at weblogic.invocation.ComponentInvocationContextManager._runAs(ComponentInvocationContextManager.java:348)
                at weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:333)
                at weblogic.work.LivePartitionUtility.doRunWorkUnderContext(LivePartitionUtility.java:54)
                at weblogic.work.PartitionUtility.runWorkUnderContext(PartitionUtility.java:41)
                at weblogic.work.SelfTuningWorkManagerImpl.runWorkUnderContext(SelfTuningWorkManagerImpl.java:640)
                at weblogic.work.ExecuteThread.execute(ExecuteThread.java:406)
                at weblogic.work.ExecuteThread.run(ExecuteThread.java:346)

And here is the relevant section of my pom, I'm not sure what's wrong with it

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.jboss.arquillian</groupId>
            <artifactId>arquillian-bom</artifactId>
            <version>1.1.13.Final</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
<dependencies>
    <dependency>
        <groupId>org.jmockit</groupId>
        <artifactId>jmockit</artifactId>
        <version>1.18</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.arquillian.junit</groupId>
        <artifactId>arquillian-junit-container</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
    </dependency>
    <dependency>
        <groupId>org.jboss.arquillian.extension</groupId>
        <artifactId>arquillian-persistence-dbunit</artifactId>
        <version>1.0.0.Alpha7</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.arquillian.protocol</groupId>
        <artifactId>arquillian-protocol-servlet</artifactId>
        <version>1.1.11.Final</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.arquillian.container</groupId>
        <artifactId>arquillian-wls-remote-12.1.x</artifactId>
        <version>1.0.1.Final</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
    </dependency>
</dependencies>

EDIT: If I remove JMockit from the dependencies list, it works! I do however need JMockit for my unit tests.


Solution

  • Ok so apparently the order of the test dependencies matters, we need the arquillian junit container and junit itself BEFORE JMockit

    <dependency>
        <groupId>org.jboss.arquillian.junit</groupId>
        <artifactId>arquillian-junit-container</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
    </dependency>
    <dependency>
        <groupId>org.jmockit</groupId>
        <artifactId>jmockit</artifactId>
        <version>1.18</version>
        <scope>test</scope>
    </dependency>