在正常情况下,使用JMockit只需要在运行单元测试时在JUnit JAR之前声明JMockit JAR。
在使用RobolecticTestRunner运行的测试中使用JMockit模拟时遇到以下StackOverflowError。
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)
在使用RobolectricTestRunner运行单元测试时,是否有任何特殊配置允许JMockit正常运行?以下讨论使其看起来像JMockit 1.5版本
RobolectricTestRunner's HelperTestRunner having trouble invoking Jmockit?
此帖子提供了创建调用Startup的自定义RobolectricTestRunner的建议。 initializeIfNeeded()
can jmockit and robolectric coexist?
但是,这两个讨论都没有帮助我确定解决方案。任何建议将不胜感激。谢谢。
答案 0 :(得分:0)
我能够使用Robolectric 2.3和JMockit 1.8(现在不要使用更高级别的JMOCKIT)来实现这个目的。
也许试试?