gpt4 book ai didi

java - Jmockit NullPointerException 与 Junit

转载 作者:行者123 更新时间:2023-11-29 06:05:52 24 4
gpt4 key购买 nike

我正在尝试运行由另一位程序员在 eclipse-indigo 中使用 JUnit 编写的测试,他确信它可以工作,但是当我尝试 Jmockit 时出现故障,我还找不到解决方案。

我尝试更改类路径中的 jmockit.jar 但不起作用。你知道这个问题吗?

编辑:当我在终端中使用“ant test”时没有问题,但是如果我在我的 IDE 中单击 run as > JUnit test 我会收到此错误。

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)

最佳答案

正如您在评论中所述,您在 ant 中为执行设置了一个额外的参数。
尝试设置

-javaagent:libtest/jmockit.jar

在您的 junit 测试的启动配置中作为 VM 参数(它是参数选项卡上的第二个输入字段)。

并确保类路径与 ant 中的相同。

enter image description here

关于java - Jmockit NullPointerException 与 Junit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8545876/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com