本文介绍了遇到问题调用Jmockit RobolectricTestRunner的HelperTestRunner?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Robolectric的IntelliJ中运行测试的问题,它看起来像jMockit可能是一个因素。我的测试本身绝对没有jmockit而事实上现在测试只是比较两个字符串。我正与一个严重依赖pretty上jmockit大codeBase的工作,所以我觉得有同有类路径jmockit的问题。 (我看到了相似但不相同的)

有没有办法来解决呢?难道我将不得不抛弃我所有jmockit测试?

测试code是:

  @RunWith(RobolectricTestRunner.class)
公共类DefaultAssetFormatterTest {    @测试
    公共无效test_asset_formatter(){
        assertThat(12345,equalTo(Fsdafadsf));
    }}

这是我所看到的,当我运行的IntelliJ测试:

  java.lang.IllegalArgumentException异常:不调用方法:公共静态无效mockit.integration.junit4.internal.MockFrameworkMethod.validatePublicVoidNoArg(mockit.Invocation,boolean,java.util.List)
    在mockit.internal.util.MethodReflection.invoke(MethodReflection.java:61)
    在mockit.internal.annotations.MockMethodBridge.callMock(MockMethodBridge.java:76)
    在mockit.internal.annotations.MockMethodBridge.invoke(MockMethodBridge.java:41)
    在org.junit.runners.model.FrameworkMethod.validatePublicVoidNoArg(FrameworkMethod.java)
    在org.junit.runners.ParentRunner.validatePublicVoidNoArgMethods(ParentRunner.java:131)
    在org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:162)
    在org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:102)
    在org.junit.runners.ParentRunner.validate(ParentRunner.java:344)
    在org.junit.runners.ParentRunner<&初始化GT;(ParentRunner.java:74)
    在org.junit.runners.BlockJUnit4ClassRunner<&初始化GT;(BlockJUnit4ClassRunner.java:55)
    在org.robolectric.RobolectricTestRunner $ HelperTestRunner<&初始化GT;(RobolectricTestRunner.java:643)
    在org.robolectric.RobolectricTestRunner.getHelperTestRunner(RobolectricTestRunner.java:261)
    在org.robolectric.RobolectricTestRunner $ 2.evaluate(RobolectricTestRunner.java:194)
    在org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    在org.junit.runners.BlockJUnit4ClassRunner.runCh​​ild(BlockJUnit4ClassRunner.java:68)
    在org.junit.runners.BlockJUnit4ClassRunner.runCh​​ild(BlockJUnit4ClassRunner.java:47)
    在org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:231)
    在org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:60)
    在org.junit.runners.ParentRunner.runCh​​ildren(ParentRunner.java:229)
    在org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:50)
    在org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:222)
    在org.robolectric.RobolectricTestRunner $ 1.evaluate(RobolectricTestRunner.java:175)
    在org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    在org.junit.runner.JUnitCore.run(JUnitCore.java:157)
    在com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77)
    在com.intellij.rt.execution.junit.JUnitStarter。prepareStreamsAndStart(JUnitStarter.java:195)
    在com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
    在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)
    在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    在com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
java.lang.IllegalArgumentException异常:引起错误的参数个数
    在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)
    在org.robolectric.RobolectricTestRunner $ HelperTestRunner<&初始化GT;(RobolectricTestRunner.java:643)
    在org.robolectric.RobolectricTestRunner.getHelperTestRunner(RobolectricTestRunner.java:261)
    在org.robolectric.RobolectricTestRunner $ 2.evaluate(RobolectricTestRunner.java:194)
    在org.robolectric.RobolectricTestRunner $ 1.evaluate(RobolectricTestRunner.java:175)
    在com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
    在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)
    ... 2个java.lang.IllegalArgumentException异常:未找到兼容的方法:fireTestRunFinished(mockit.Invocation,org.junit.runner.Result)
    在mockit.internal.util.MethodReflection.findCompatibleMethod(MethodReflection.java:138)
    在mockit.internal.annotations.MockState.getMockMethod(MockState.java:112)
    在mockit.internal.annotations.AnnotatedMockStates.getMockMethod(AnnotatedMockStates.java:109)
    在mockit.internal.annotations.MockMethodBridge.callMock(MockMethodBridge.java:65)
    在mockit.internal.annotations.MockMethodBridge.invoke(MockMethodBridge.java:41)
    在org.junit.runner.notification.RunNotifier.fireTestRunFinished(RunNotifier.java)
    在org.junit.runner.JUnitCore.run(JUnitCore.java:158)
    在com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77)
    在com.intellij.rt.execution.junit.JUnitStarter。prepareStreamsAndStart(JUnitStarter.java:195)
    在com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
    在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)
    在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    在java.lang.reflect.Method.invoke(Method.java:597)
    在com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)


解决方案

您将不得不升级到JMockit 1.5 ,以避免这个问题。

这是因为JMockit未能在Robolectric的 AsmInstrumentingClassLoader 的presence工作的。 JMockit的1.5版使得它更健壮的环境中使用自定义类加载。

I'm having problems running tests in IntelliJ using Robolectric and it looks like jMockit might be a factor. My test itself has absolutely no jmockit and in fact the test is now just comparing two strings. I'm working with a large codebase that relies pretty heavily on jmockit, so I think there's an issue with the classpath having jmockit. (I saw something similar but not the same at can jmockit and robolectric coexist?)

Is there a way to work around this? Am I going to have to blow away all my jmockit tests?

The test code is:

@RunWith(RobolectricTestRunner.class)
public class DefaultAssetFormatterTest {

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

}

This is what I see when I run the test in 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)
解决方案

You are going to have to upgrade to JMockit 1.5 to avoid this problem.

It occurs because of JMockit's inability to work in the presence of Robolectric's AsmInstrumentingClassLoader. Version 1.5 of JMockit makes it more robust in environments with custom classloading.

这篇关于遇到问题调用Jmockit RobolectricTestRunner的HelperTestRunner?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 19:02