我在编写单元测试时遇到了麻烦,因为我在尝试创建EquifaxDLPingRequest类的新对象时遇到此异常。我已经简化了代码以显示问题:
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
@PrepareForTest({EquifaxDLPingRequest.class})
public class SimpleTest {
@Test
public void test() {
EquifaxDLPingRequest equifaxDLPingRequest = new EquifaxDLPingRequest("");
}
}
当创建 equifaxDLPingRequest 时,我有这个例外:
java.lang.VerifyError: Inconsistent stackmap frames at branch target 46
Exception Details:
Location:
com/dealflo/vhub/maintenance/passwordchanger/AbstractMaintenanceRequest.<init>(Lorg/powermock/core/IndicateReloadClass;)V @46: aload_2
Reason:
Type uninitializedThis (current frame, locals[2]) is not assignable to 'com/dealflo/vhub/maintenance/passwordchanger/AbstractMaintenanceRequest' (stack map, locals[2])
Current Frame:
bci: @32
flags: { flagThisUninit }
locals: { uninitializedThis, 'org/powermock/core/IndicateReloadClass', uninitializedThis, 'org/powermock/core/IndicateReloadClass', top, 'java/lang/Object' }
stack: { 'java/lang/Object', 'java/lang/Object' }
Stackmap Frame:
bci: @46
flags: { flagThisUninit }
locals: { uninitializedThis, 'org/powermock/core/IndicateReloadClass', 'com/dealflo/vhub/maintenance/passwordchanger/AbstractMaintenanceRequest', 'org/powermock/core/IndicateReloadClass' }
stack: { }
Bytecode:
0000000: 2a2b 4e4d 12d7 b800 6a04 bd00 1b59 032d
0000010: 5312 d8b8 00ce b800 da3a 0519 05b2 002b
0000020: a500 0e2a 01c0 002d b700 dca7 000a 2c2d
0000030: b700 dc01 57b1
Stackmap Table:
append_frame(@46,Object[#16],Object[#45])
chop_frame(@53,2)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at javassist.runtime.Desc.getClassObject(Desc.java:44)
at javassist.runtime.Desc.getClassType(Desc.java:153)
at javassist.runtime.Desc.getType(Desc.java:123)
at javassist.runtime.Desc.getType(Desc.java:79)
at com.dealflo.vhub.maintenance.passwordchanger.SimpleTest.test(SimpleTest.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:66)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:310)
at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:86)
at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:94)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:294)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTestInSuper(PowerMockJUnit47RunnerDelegateImpl.java:127)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTest(PowerMockJUnit47RunnerDelegateImpl.java:82)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:282)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:84)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:49)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:207)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:146)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$1.run(PowerMockJUnit44RunnerDelegateImpl.java:120)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:122)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:106)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)
at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
只有在我添加@PrepareForTest({EquifaxDLPingRequest.class})时才会出现异常,但我必须使用PowerMockito和@PrepareForTest({EquifaxDLPingRequest.class}),因为稍后我必须模拟一个局部变量。 我知道 -XX:-UseSplitVerifier 和 -noverify jvm选项,但我不能在我的项目中使用它们。 任何人都可以解释为什么会这样,我该如何解决?