1

Under normal circumstances, using JMockit only requires that the JMockit JARs be declared before the JUnit JAR when running unit tests.

I am encountering the following StackOverflowError when using JMockit mocks in tests run with the RobolecticTestRunner.

java.lang.StackOverflowError: null
    at java.lang.ThreadLocal.getMap(ThreadLocal.java:213)
    at java.lang.ThreadLocal.get(ThreadLocal.java:144)
    at mockit.internal.mockups.MockState.update(MockState.java:54)
    at mockit.internal.mockups.MockStates.updateMockState(MockStates.java:93)
    at mockit.internal.state.TestRun.updateMockState(TestRun.java:160)
    at org.junit.runners.model.FrameworkMethod.validatePublicVoidNoArg(FrameworkMethod.java)
    at mockit.integration.junit4.internal.MockFrameworkMethod.validatePublicVoidNoArg(MockFrameworkMethod.java:46)
    at sun.reflect.GeneratedMethodAccessor12.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at mockit.internal.util.MethodReflection.invokeWithCheckedThrows(MethodReflection.java:106)
    at mockit.internal.mockups.MockMethodBridge.callMock(MockMethodBridge.java:85)
    at mockit.internal.mockups.MockMethodBridge.invoke(MockMethodBridge.java:44)
    at org.junit.runners.model.FrameworkMethod.validatePublicVoidNoArg(FrameworkMethod.java)
    at mockit.integration.junit4.internal.MockFrameworkMethod.validatePublicVoidNoArg(MockFrameworkMethod.java:46)
    at sun.reflect.GeneratedMethodAccessor12.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at mockit.internal.util.MethodReflection.invokeWithCheckedThrows(MethodReflection.java:106)
    at mockit.internal.mockups.MockMethodBridge.callMock(MockMethodBridge.java:85)
    at mockit.internal.mockups.MockMethodBridge.invoke(MockMethodBridge.java:44)
    at org.junit.runners.model.FrameworkMethod.validatePublicVoidNoArg(FrameworkMethod.java)

Is there any special configuration that would allow for JMockit to function correctly when running unit tests with RobolectricTestRunner? The following discussion makes it look like JMockit with 1.5 release

RobolectricTestRunner's HelperTestRunner having trouble invoking Jmockit?

and this posting provided a suggestion for creating a custom RobolectricTestRunner that invokes Startup. initializeIfNeeded()

can jmockit and robolectric coexist?

However, neither discussion has helped me identify a solution. Any suggestions will be appreciated. Thank you.

Community
  • 1
  • 1
jlchoike
  • 11
  • 1
  • I managed to run a `@RunWith(RobolectricTestRunner.class)` test class with JMockit 1.7 also on the classpath, with no errors. I just needed to put `android.jar` after `junit.jar`, since Android includes some JUnit 3.8 classes (like `junit.framework.TestCase`). Can you provide more details so I could try and reproduce the problem? – Rogério Apr 15 '14 at 20:43
  • I am executing my tests from Maven with dependencies declared in the following order: – jlchoike Apr 16 '14 at 11:06
  • I am executing my tests from Maven with dependencies declared in the following order (dependency version in parentheses): 1. JMockit (1.7) 2. JUnit (4.8.2) 3. Robolectric (2.2) 4. Android SDK (2.3.3_r2) The JUnit tests are implemented using JUnit 4 annotations – jlchoike Apr 16 '14 at 11:16
  • Ok, I managed to reproduce the exception, so I will be trying to figure out a solution or workaround. It only happens in test classes with the `RobolectricTestRunner`; test classes only using JMockit appear to work fine. – Rogério Apr 16 '14 at 15:53

1 Answers1

0

I was able to get this working using Robolectric 2.3 and JMockit 1.8 (DO NOT USE HIGHER VERSION OF JMOCKIT for now)

maybe try that?

David T.
  • 22,301
  • 23
  • 71
  • 123
  • Thanks for confirming. This issue was resolved by Rogerio after reporting this issue (released in 1.8) – jlchoike Aug 06 '14 at 18:34