verifyEqual
Class: matlab.unittest.qualifications.Verifiable
Namespace: matlab.unittest.qualifications
Verify value is equal to specified value
Syntax
Description
verifyEqual(
verifies that testCase
,actual
,expected
)actual
is strictly equal to
expected
. If expected
is not a MATLAB® or Java® object, actual
and expected
must
have the same class, size, and value for the test to pass. verifyEqual
compares actual
and expected
in the same way as
the IsEqualTo
constraint.
verifyEqual(
also associates the diagnostic information in testCase
,actual
,expected
,diagnostic
)diagnostic
with the qualification.
verifyEqual(___,
verifies equality with additional options specified by one or more name-value arguments.
Specify the name-value arguments after all of the arguments in any of the previous syntaxes.
In R2021a and earlier, specify the name-value arguments before
Name,Value
)diagnostic
.
Input Arguments
Examples
Tips
verifyEqual
is a convenience method. For example,verifyEqual(testCase,actual,expected)
is functionally equivalent to the following code.import matlab.unittest.constraints.IsEqualTo testCase.verifyThat(actual,IsEqualTo(expected))
Similarly,
verifyEqual(testCase,actual,expected,"AbsTol",abstol,"RelTol",reltol)
is functionally equivalent to the following code.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)))
More functionality is available when using the
IsEqualTo
,AbsoluteTolerance
, andRelativeTolerance
constraints directly viaverifyThat
.Use verification qualifications to produce and record failures without throwing an exception. Because verifications do not throw exceptions, all test content runs to completion even when verification failures occur. Typically, verifications are the primary qualification for a unit test because they typically do not require an early exit from the test. Use other qualification types to test for violation of preconditions or incorrect test setup:
Use assumption qualifications to ensure that the test environment meets preconditions that otherwise do not result in a test failure. Assumption failures result in filtered tests, and the testing framework marks the tests as
Incomplete
. For more information, seematlab.unittest.qualifications.Assumable
.Use assertion qualifications when the failure condition invalidates the remainder of the current test content but does not prevent proper execution of subsequent tests. A failure at the assertion point renders the current test as
Failed
andIncomplete
. For more information, seematlab.unittest.qualifications.Assertable
.Use fatal assertion qualifications to abort the test session upon failure. These qualifications are useful when the failure is so fundamental that continuing testing does not make sense. Fatal assertion qualifications are also useful when fixture teardown does not restore the environment state correctly, and aborting testing and starting a fresh session is preferable. For more information, see
matlab.unittest.qualifications.FatalAssertable
.