2015-08-16 34 views
10

我开发的Eclipse开普勒的插件。添加@RunWith(JMockit.class)到我的测试类导致以下错误:JMockIt失败AgentInitializationException:代理JAR加载,但代理初始化失败

JMockit: Reinitializing under custom class loader [email protected][com.mypackage.myclass:2.3.9.201508161221(id=1)] 
java.lang.reflect.InvocationTargetException 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
     at java.lang.reflect.Method.invoke(Method.java:606) 
     at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:382) 
     at sun.instrument.InstrumentationImpl.loadClassAndCallAgentmain(InstrumentationImpl.java:407) 
Caused by: java.lang.VerifyError 
     at sun.instrument.InstrumentationImpl.redefineClasses0(Native Method) 
     at sun.instrument.InstrumentationImpl.redefineClasses(InstrumentationImpl.java:170) 
     at mockit.internal.startup.Startup.redefineMethods(Startup.java:242) 
     at mockit.internal.startup.Startup.redefineMethods(Startup.java:236) 
     at mockit.internal.mockups.MockClassSetup.applyClassModifications(MockClassSetup.java:134) 
     at mockit.internal.mockups.MockClassSetup.redefineMethodsInClassHierarchy(MockClassSetup.java:91) 
     at mockit.internal.mockups.MockClassSetup.redefineMethods(MockClassSetup.java:76) 
     at mockit.MockUp.redefineMethods(MockUp.java:240) 
     at mockit.MockUp.redefineClassOrImplementInterface(MockUp.java:222) 
     at mockit.MockUp.<init>(MockUp.java:131) 
     at mockit.integration.junit4.internal.RunNotifierDecorator.<init>(RunNotifierDecorator.java:21) 
     at mockit.internal.startup.JMockitInitialization.loadInternalStartupMocksForJUnitIntegration(JMockitInitialization.java:42) 
     at mockit.internal.startup.JMockitInitialization.initialize(JMockitInitialization.java:27) 
     at mockit.internal.startup.Startup.applyStartupMocks(Startup.java:72) 
     at mockit.internal.startup.Startup.reapplyStartupMocks(Startup.java:124) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
     at java.lang.reflect.Method.invoke(Method.java:606) 
     at mockit.internal.util.MethodReflection.invoke(MethodReflection.java:94) 
     at mockit.internal.util.MethodReflection.invoke(MethodReflection.java:159) 
     at mockit.internal.startup.Startup.reinitializeJMockitUnderCustomClassLoader(Startup.java:118) 
     at mockit.internal.startup.Startup.agentmain(Startup.java:101) 
     ... 6 more 
java.lang.IllegalStateException: com.sun.tools.attach.AgentInitializationException: Agent JAR loaded but agent failed to initialize 
     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
     at java.lang.reflect.Constructor.newInstance(Constructor.java:526) 
     at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:262) 
     at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153) 
     at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:606) 
     at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray2(ReflectionUtils.java:208) 
     at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:156) 
     at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:82) 
     at org.eclipse.tycho.surefire.osgibooter.OsgiSurefireBooter.run(OsgiSurefireBooter.java:91) 
     at org.eclipse.tycho.surefire.osgibooter.AbstractUITestApplication$1.run(AbstractUITestApplication.java:35) 
     at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35) 
     at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135) 
     at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4145) 
     at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3762) 
     at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1113) 
     at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332) 
     at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:997) 
     at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:140) 
     at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:611) 
     at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332) 
     at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:567) 
     at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150) 
     at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124) 
     at org.eclipse.tycho.surefire.osgibooter.UITestApplication.runApplication(UITestApplication.java:31) 
     at org.eclipse.tycho.surefire.osgibooter.AbstractUITestApplication.run(AbstractUITestApplication.java:120) 
     at org.eclipse.tycho.surefire.osgibooter.UITestApplication.start(UITestApplication.java:37) 
     at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196) 
     at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110) 
     at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79) 
     at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:354) 
     at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:181) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:606) 
     at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636) 
     at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591) 
     at org.eclipse.equinox.launcher.Main.run(Main.java:1450) 
     at org.eclipse.equinox.launcher.Main.main(Main.java:1426) 
Caused by: com.sun.tools.attach.AgentInitializationException: Agent JAR loaded but agent failed to initialize 
     ... 39 more 

上午我做错了什么,或者它是一个JMockIt错误?我使用的版本JMockIt 1.18,JUnit的4.12

+0

http://stackoverflow.com/questions/2905735/jmockit-initialization-problem的可能的复制 – Rossiar

回答

2

我预计@RunWith(JMockit.class)应该采取这个问题的关心。

在任何情况下,从JMockit教程here,也有一些注意事项,你应该检查,在情况下,这些解决您的问题。尤其是,这两个似乎是最相关的:

  • (Note for Eclipse users: when specifying the order of jars in the >classpath, make sure to use the "Order and Export" tab of the "Java Build >Path" window. Also, make sure the Eclipse project uses the JRE from a JDK >installation instead of a "plain" JRE, since the latter lacks the >"attach" native library.)
  • In other situations (like running on JDK implementations other than >the Oracle JDKs), you may need to pass "-javaagent:path>/jmockit.jar" as a JVM initialization parameter. This can be done in >the "Run/Debug Configuration" for both Eclipse and IntelliJ IDEA, or with >build tools such as Ant and Maven.
+0

我使用Oracle JDK,所以它不应该成为问题。 – Sergey

+0

你检查的第一个点,即在订单和出口标签的JUnit之前指定jmockit? – JChrist

+0

是的,我做到了。它也只需要,如果你不使用@RunWith(MockitoJUnit44Runner.class)注释。 – Sergey

0

右键点击您的项目在Package Explorer中

click Properties. go to Java Build Path. Libraries tab. click on 'Add Library' button select JUnit click Next. You should be able to handle it from there.

后,如果您使用的覆盖率:你将能够看到的覆盖面。