我正在尝试在一个类中执行两个测试用例,第一个测试方法是一个例外,第二个是断言测试方法。 因此,在第二种方法中创建对象时,它将引发异常。 当我从第一个测试方法中删除例外异常时,它将很好执行。
@PrepareForTest({ CompanyBDL.class })
public class Sample extends TestCaseExecutor {
@Test(expectedExceptions = CompanyBDLException.class)
public void testSaveCompanyException() throws Exception {
//code
}
@Test(priority = 4, groups = "Negative", description = "Test getGrandParentsForGivenParentCode with Valid test data")
public void testGetGrandParentsForGivenParentCode() throws Exception {
CompanyBDL companyBDL = new CompanyBDL(null);
//code
}
}
运行测试时,出现以下错误
java.lang.VerifyError: Stack map does not match the one at exception handler 315
Exception Details:
Location:
com/newport/moonshot/mdm/bdl/response/CompanyResponseBDL.getResponseFieldValue(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; @315: astore
Reason:
Type 'com/newport/moonshot/mdm/bdl/exception/CompanyBDLException' (current frame, stack[0]) is not assignable to 'com/newport/moonshot/exception/MoonshotBaseException' (stack map, stack[0])
Current Frame:
bci: @3
flags: { }
locals: { 'com/newport/moonshot/mdm/bdl/response/CompanyResponseBDL', 'java/lang/String', 'java/lang/Object', 'java/lang/String' }
stack: { 'com/newport/moonshot/mdm/bdl/exception/CompanyBDLException' }
Stackmap Frame:
bci: @315
flags: { }
locals: { 'com/newport/moonshot/mdm/bdl/response/CompanyResponseBDL', 'java/lang/String', 'java/lang/Object', 'java/lang/Object' }
stack: { 'com/newport/moonshot/exception/MoonshotBaseException' }
Bytecode:
0x0000000: 1215 4e2b b800 1799 0136 2cc6 0132 2b59
0x0000010: 3a04 b600 1dab 0000 0000 011c 0000 0007
0x0000020: a6c7 3e3f 0000 0043 b862 b143 0000 0050
0x0000030: ba4c 4a22 0000 005d c9c8 c958 0000 006a
0x0000040: cf14 cf1f 0000 0077 224b f011 0000 0084
0x0000050: 47cb a1e8 0000 0091 1904 1223 b600 259a
0x0000060: 0054 a700 cf19 0412 29b6 0025 9a00 71a7
0x0000070: 00c2 1904 122b b600 259a 0079 a700 b519
0x0000080: 0412 2db6 0025 9a00 96a7 00a8 1904 122f
0x0000090: b600 259a 0074 a700 9b19 0412 31b6 0025
0x00000a0: 9a00 67a7 008e 1904 1233 b600 259a 001b
0x00000b0: a700 81bb 004e 59b8 0050 b700 562c b600
0x00000c0: 58b6 005e 4ea7 0078 bb00 6159 b800 50b7
0x00000d0: 0063 2cb6 0058 b600 644e a700 63bb 0067
0x00000e0: 59b8 0050 b700 692c b600 58b6 006a 4ea7
0x00000f0: 004e bb00 6d59 b800 50b7 006f 2cb6 0058
0x0000100: b600 704e a700 39bb 0073 59b8 0050 b700
0x0000110: 752c b600 58b6 0076 4ea7 0024 bb00 7959
0x0000120: b800 50b7 007b 2cb6 0058 b600 7c4e a700
0x0000130: 0f2a 2b2c b700 7f4e a700 053a 042d c700
0x0000140: 0612 154e 2db0
Exception Handler Table:
bci [3, 312] => handler: 315
bci [3, 312] => handler: 315
bci [3, 312] => handler: 315
bci [3, 312] => handler: 315
bci [3, 312] => handler: 315
bci [3, 312] => handler: 315
Stackmap Table:
append_frame(@88,Object[#89],Object[#30])
same_frame(@101)
same_frame(@114)
same_frame(@127)
same_frame(@140)
same_frame(@153)
same_frame(@166)
same_frame(@179)
same_frame(@200)
same_frame(@221)
same_frame(@242)
same_frame(@263)
same_frame(@284)
same_frame(@305)
full_frame(@315,{Object[#1],Object[#30],Object[#89],Object[#89]},{Object[#144]})
same_frame(@317)
same_frame(@324)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at javassist.runtime.Desc.getClassObject(Desc.java:43)
at javassist.runtime.Desc.getClassType(Desc.java:152)
at javassist.runtime.Desc.getType(Desc.java:122)
at javassist.runtime.Desc.getType(Desc.java:78)
at com.newport.moonshot.mdm.bdl.CompanyBDL.<init>(CompanyBDL.java:55)
at com.newport.moonshot.mdm.bdl.Sample.testGetGrandParentsForGivenParentCode(Sample.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at com.newport.moonshot.test.executor.HookCallBack.invokeMethod(HookCallBack.java:11)
at com.newport.moonshot.test.executor.TestCaseExecutor.run(TestCaseExecutor.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:212)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:707)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
public class CompanyResponseBDL extends ResponseBDL<Company> {
@Override
public Object getResponseFieldValue(String fieldId, Object fieldValue) throws ResponseFieldsException {
Object responseFieldValue = "";
try {
// Some piece of code
} catch (G4CodeBDLException | TypeValueBDLException | CurrencyBDLException | TermBDLException | VATCodeBDLException | CompanyBDLException e) {
}
if(responseFieldValue == null) {
responseFieldValue = "";
}
return responseFieldValue;
}
}