我正在尝试运行一个由另一个程序员用JUnit在eclipse-indigo中编写的测试,他确信它有效,但是当我尝试Jmockit时出现故障,我找不到解决方案了。 / p>
我尝试在类路径中更改jmockit.jar但不工作。你对这个问题有什么看法吗?
编辑:当我在终端中使用“ant test”时没有问题,但如果我点击运行为>在我的IDE中进行JUnit测试我遇到了这个错误。
Exception in thread "(Attach Listener)" java.lang.reflect.InvocationTargetException
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 sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:323)
at sun.instrument.InstrumentationImpl.loadClassAndCallAgentmain(InstrumentationImpl.java:348)
Caused by: java.lang.NullPointerException
at mockit.internal.state.TestRun.getInstance(TestRun.java:40)
at mockit.internal.state.TestRun.mockFixture(TestRun.java:111)
at mockit.internal.ClassFile.createClassFileReader(ClassFile.java:33)
at mockit.internal.annotations.AnnotatedMockMethodCollector.collectMockMethods(AnnotatedMockMethodCollector.java:39)
at mockit.internal.RedefinitionEngine.<init>(RedefinitionEngine.java:86)
at mockit.internal.RedefinitionEngine.<init>(RedefinitionEngine.java:110)
at mockit.internal.startup.Startup.setUpInternalStartupMock(Startup.java:130)
at mockit.internal.startup.Startup.loadInternalStartupMocksForJUnitIntegration(Startup.java:112)
at mockit.internal.startup.Startup.initialize(Startup.java:79)
at mockit.internal.startup.Startup.agentmain(Startup.java:69)
... 6 more
Agent failed to start!
[WARN ][load ] agent library 'instrument' failed to init with result: 102
java.lang.RuntimeException: com.sun.tools.attach.AgentInitializationException: Agent JAR loaded but agent failed to initialize
at mockit.internal.startup.JDK6AgentLoader.loadAgentAndDetachFromThisVM(JDK6AgentLoader.java:130)
at mockit.internal.startup.JDK6AgentLoader.loadAgent(JDK6AgentLoader.java:80)
at mockit.internal.startup.AgentInitialization.initializeAccordingToJDKVersion(AgentInitialization.java:41)
at mockit.internal.startup.Startup.initializeIfNeeded(Startup.java:244)
at org.junit.runner.Runner.<clinit>(Runner.java:25)
at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:13)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:30)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:32)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:41)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:31)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:455)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:684)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:391)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: com.sun.tools.attach.AgentInitializationException: Agent JAR loaded but agent failed to initialize
at sun.tools.attach.HotSpotVirtualMachine.loadAgent(HotSpotVirtualMachine.java:122)
at mockit.internal.startup.JDK6AgentLoader.loadAgentAndDetachFromThisVM(JDK6AgentLoader.java:123)
at mockit.internal.startup.JDK6AgentLoader.loadAgent(JDK6AgentLoader.java:81)
... 16 more
java.lang.NoClassDefFoundError: org/junit/internal/runners/ErrorReportingRunner
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:32)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:41)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:31)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
答案 0 :(得分:3)
正如你在评论中所述,你为蚂蚁的执行设置了一个额外的论据 尝试设置
-javaagent:libtest/jmockit.jar
作为junit测试的启动配置中的VM Argument(它是Arguments选项卡上的第二个输入字段)。
确保类路径与ant相同。
答案 1 :(得分:0)
如果你有分布的zip文件,那么调试它应该很容易,看看为什么它会得到NPE。只需将源附件添加为zip文件即可。