RobolectricTestRunner的HelperTestRunner无法调用Jmockit?

时间:2013-10-18 01:57:53

标签: android intellij-idea robolectric jmockit

我在使用Robolectric在IntelliJ中运行测试时遇到问题,看起来jMockit可能是一个因素。我的测试本身绝对没有jmockit,实际上测试现在只是比较两个字符串。我正在使用一个非常依赖于jmockit的大型代码库,所以我认为类路径有jmockit存在问题。 (我在can jmockit and robolectric coexist?

看到类似但不一样的东西

有办法解决这个问题吗?我是否必须吹走所有的jmockit测试?

测试代码是:

@RunWith(RobolectricTestRunner.class)
public class DefaultAssetFormatterTest {

    @Test
    public void test_asset_formatter() {
        assertThat("12345", equalTo("Fsdafadsf"));
    }

}

这是我在IntelliJ中运行测试时看到的:

java.lang.IllegalArgumentException: Failure to invoke method: public static void mockit.integration.junit4.internal.MockFrameworkMethod.validatePublicVoidNoArg(mockit.Invocation,boolean,java.util.List)
    at mockit.internal.util.MethodReflection.invoke(MethodReflection.java:61)
    at mockit.internal.annotations.MockMethodBridge.callMock(MockMethodBridge.java:76)
    at mockit.internal.annotations.MockMethodBridge.invoke(MockMethodBridge.java:41)
    at org.junit.runners.model.FrameworkMethod.validatePublicVoidNoArg(FrameworkMethod.java)
    at org.junit.runners.ParentRunner.validatePublicVoidNoArgMethods(ParentRunner.java:131)
    at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:162)
    at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:102)
    at org.junit.runners.ParentRunner.validate(ParentRunner.java:344)
    at org.junit.runners.ParentRunner.<init>(ParentRunner.java:74)
    at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:55)
    at org.robolectric.RobolectricTestRunner$HelperTestRunner.<init>(RobolectricTestRunner.java:643)
    at org.robolectric.RobolectricTestRunner.getHelperTestRunner(RobolectricTestRunner.java:261)
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:194)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:175)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.IllegalArgumentException: wrong number of arguments
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at org.robolectric.RobolectricTestRunner$HelperTestRunner.<init>(RobolectricTestRunner.java:643)
    at org.robolectric.RobolectricTestRunner.getHelperTestRunner(RobolectricTestRunner.java:261)
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:194)
    at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:175)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    ... 2 more

java.lang.IllegalArgumentException: No compatible method found: fireTestRunFinished(mockit.Invocation, org.junit.runner.Result)
    at mockit.internal.util.MethodReflection.findCompatibleMethod(MethodReflection.java:138)
    at mockit.internal.annotations.MockState.getMockMethod(MockState.java:112)
    at mockit.internal.annotations.AnnotatedMockStates.getMockMethod(AnnotatedMockStates.java:109)
    at mockit.internal.annotations.MockMethodBridge.callMock(MockMethodBridge.java:65)
    at mockit.internal.annotations.MockMethodBridge.invoke(MockMethodBridge.java:41)
    at org.junit.runner.notification.RunNotifier.fireTestRunFinished(RunNotifier.java)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:158)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

1 个答案:

答案 0 :(得分:2)

您将不得不升级到JMockit 1.5 以避免此问题。

这是因为JMockit无法在Robolectric的AsmInstrumentingClassLoader存在的情况下工作。 JMockit 1.5版使其在具有自定义类加载的环境中更加健壮。