verifyEqual
类: matlab.unittest.qualifications.Verifiable
命名空间: matlab.unittest.qualifications
确认值等于指定值
语法
说明
verifyEqual(
还将 testCase
,actual
,expected
,diagnostic
)diagnostic
中的诊断信息与鉴定相关联。
verifyEqual(___,
通过一个或多个名称-值参量指定的其他选项确认相等性。需要在上述任一语法中的所有参量之后指定名称-值参量。在 R2021a 及更早版本中,请在 Name,Value
)diagnostic
之前指定名称-值参量。
输入参数
示例
提示
verifyEqual
方法非常方便。例如,verifyEqual(testCase,actual,expected)
在功能上等效于以下代码。import matlab.unittest.constraints.IsEqualTo testCase.verifyThat(actual,IsEqualTo(expected))
同样,
verifyEqual(testCase,actual,expected,"AbsTol",abstol,"RelTol",reltol)
在功能上等效于以下代码。import matlab.unittest.constraints.IsEqualTo import matlab.unittest.constraints.AbsoluteTolerance import matlab.unittest.constraints.RelativeTolerance testCase.verifyThat(actual,IsEqualTo(expected, ... "Within",AbsoluteTolerance(abstol) | RelativeTolerance(reltol)))
当直接通过
verifyThat
使用IsEqualTo
、AbsoluteTolerance
和RelativeTolerance
约束时,可利用更多功能。使用此确认在不引发异常的条件下生成和记录失败。由于确认不会引发异常,因此即使出现确认失败的情形,依然会完成所有的测试内容。通常,确认指的是对单元测试的主要鉴定,因为这些确认一般不要求提前从测试中退出。使用其他鉴定类型来测试是否违反先决条件或测试安装是否正确:
使用断言鉴定确保测试环境满足无论如何都不会导致测试失败的先决条件。假设失败会生成已过滤的测试,且测试框架会将测试设为
Incomplete
。有关详细信息,请参阅matlab.unittest.qualifications.Assumable
。当失败条件导致当前测试内容的剩余部分都失效,但不会阻止后续测试正确执行时,使用断言鉴定。断言点处的失败会将当前测试展现为
Failed
和Incomplete
。有关详细信息,请参阅matlab.unittest.qualifications.Assertable
。使用致命断言鉴定在失败时中止测试会话。当失败涉及根本以致继续测试已经没有意义时,这些鉴定非常有用。当脚手架拆解不能正确还原环境状态,适合中止测试并启动一个新会话时,致命断言也很有用。有关详细信息,请参阅
matlab.unittest.qualifications.FatalAssertable
。