我创建了一些单元测试,其中一个需要测试在发生一系列非法活动后抛出异常.这是一组实用程序代码,因此预计某些程序员将来会在某个时刻输入无效/非法值.
我看到这个问题使用了Ada单元测试框架 - 在目前的情况下,这不是一个选择; 但是,我可以重新使用它们以便能够使用它(我的理解是将单元测试项目添加到现有的遗留代码库是一个耗时的过程).
那么 - 我应该填写这个函数的主体,以便只有在遇到多个异常时才返回true?
--* Returns true if an exception is yielded for test cases 5 and 6
function VerifyInvalidValuesCauseExceptions return Boolean is
begin
--Run tests for 5 and 6, assert that exception is thrown for each
--Not exactly sure how to do this yet
return false;
end;
Run Code Online (Sandbox Code Playgroud)
Raising_An_Exception :
begin
Should_Raise_A_Constraint_Error;
Ahven.Fail (Message => "Exception not raised as expected.");
exception
when Constraint_Error =>
null;
end Raising_An_Exception;
Run Code Online (Sandbox Code Playgroud)