delphi – CheckException只接受0参数方法;如何测试其他方法抛出
发布时间:2020-12-15 10:19:57 所属栏目:大数据 来源:网络整理
导读:我想知道什么是测试在dunit中的异常的最佳实践。我对Delphi中的方法指针不是很熟悉。是否有可能绑定参数到方法指针,以便它可以没有参数调用。目前我总是写一个附加的方法,这手动“绑定”。如果SUT有很多抛出方法,这将是恼人的。 // What i did before i k
我想知道什么是测试在dunit中的异常的最佳实践。我对Delphi中的方法指针不是很熟悉。是否有可能绑定参数到方法指针,以便它可以没有参数调用。目前我总是写一个附加的方法,这手动“绑定”。如果SUT有很多抛出方法,这将是恼人的。
// What i did before i knew abput CheckExcepion procedure MyTest.MyMethod_BadInput_Throws; var res: Boolean; begin res := false; try sut.MyMethod('this is bad'); except on e : MyExpectedException do: res := true; end; CheckTrue(res); end; // What i do now procedure MyTest.MyMethodWithBadInput; begin sut.MyMethod('this is bad'); end; procedure MyTest.MyMethod_BadInput_Throws; begin CheckException(MyMethodWithBadInput,MyExpectedException); end; // this would be nice procedure MyTest.MyMethod_BadInput_Throws; begin CheckException( BindArguments(sut.MyMethod,'this is bad'),// <-- how to do this MyExpectedException); end; 解决方法
你可以使用StartExpectingException包围你的方法调用)。
StartExpectingException(MyException); MyMethod(MyParam); StopExpectingException(); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容