matlab.unittest.qualifications.Verifiable.verifyNotSameHandle - Verify two handle arrays are different - MATLAB (original) (raw)
Class: matlab.unittest.qualifications.Verifiable
Namespace: matlab.unittest.qualifications
Verify two handle arrays are different
Syntax
Description
verifyNotSameHandle([testCase](#bt00q51-1%5Fsep%5Fmw%5F8d5e73c7-bacb-46a7-a1c1-f24af91e6c03),[actual](#mw%5F7a6236ca-31ba-47f1-8b1f-009de83c5efc),[prohibited](#mw%5Fa524354e-be57-4341-b244-aa6b2a3a82a8))
verifies that actual
is not the same as the prohibited handle array. Two handle arrays are the same if they have the same size and their corresponding elements refer to the same handle object.
verifyNotSameHandle([testCase](#bt00q51-1%5Fsep%5Fmw%5F8d5e73c7-bacb-46a7-a1c1-f24af91e6c03),[actual](#mw%5F7a6236ca-31ba-47f1-8b1f-009de83c5efc),[prohibited](#mw%5Fa524354e-be57-4341-b244-aa6b2a3a82a8),[diagnostic](#mw%5F746ff069-1e2b-4fbd-975b-63129f51789a))
also associates the diagnostic information in diagnostic
with the qualification.
Input Arguments
Test case, specified as a matlab.unittest.qualifications.Verifiable
object. Because the matlab.unittest.TestCase class subclasses matlab.unittest.qualifications.Verifiable
and inherits its methods, testCase
is typically amatlab.unittest.TestCase
object.
Value to test, specified as a value of any data type.
Value to compare against, specified as a handle array.
Diagnostic information to display when the qualification passes or fails, specified as a string array, character array, function handle, or array of matlab.automation.diagnostics.Diagnostic objects.
Depending on the test runner configuration, the testing framework can display diagnostics when the qualification passes or fails. By default, the framework displays diagnostics only when the qualification fails. You can override the default behavior by customizing the test runner. For example, use a DiagnosticsOutputPlugin instance to display both failing and passing event diagnostics.
Example: "My Custom Diagnostic"
Example: @dir
Examples
Test if the actual value is not the same as the specified handle array.
In a file in your current folder, create the ExampleHandle
handle class.
classdef ExampleHandle < handle properties Number = 1; end end
Create two ExampleHandle
objects assigned to the variables h1
and h2
. Then, assign the value of h2
to another variable h3
. The variables h1
and h2
point to different objects, but the variables h2
and h3
point to the same object.
h1 = ExampleHandle; h2 = ExampleHandle; h3 = h2;
Create a test case for interactive testing.
testCase = matlab.unittest.TestCase.forInteractiveUse;
Verify that h1
and h2
point to different objects.
verifyNotSameHandle(testCase,h1,h2)
Test if h2
and h3
point to different objects. The test fails.
verifyNotSameHandle(testCase,h2,h3, ... "Values must point to different objects.")
Verification failed. ---------------- Test Diagnostic: ---------------- Values must point to different objects. --------------------- Framework Diagnostic: --------------------- verifyNotSameHandle failed. --> The two handles must not refer to the same handle, or should have different sizes.
Actual Value:
ExampleHandle with properties:
Number: 1
Prohibited Handle Object:
ExampleHandle with properties:
Number: 1
------------------
Stack Information:
------------------
In C:\work\TestHandlesForInequalityExample.m (TestHandlesForInequalityExample) at 33
Verify that [h1 h2]
is not the same as [h2 h1]
. The test passes because the corresponding vector elements point to different objects.
verifyNotSameHandle(testCase,[h1 h2],[h2 h1])
Test if [h2 h3]
is not the same as [h3 h2]
. The test fails because the corresponding vector elements point to the same object.
verifyNotSameHandle(testCase,[h2 h3],[h3 h2])
Verification failed. --------------------- Framework Diagnostic: --------------------- verifyNotSameHandle failed. --> The two handles must not refer to the same handle, or should have different sizes.
Actual Value:
1×2 ExampleHandle array with properties:
Number
Prohibited Handle Object:
1×2 ExampleHandle array with properties:
Number
------------------
Stack Information:
------------------
In C:\work\TestHandlesForInequalityExample.m (TestHandlesForInequalityExample) at 44
Verify that two handle arrays of different shapes are not the same.
verifyNotSameHandle(testCase,[h1 h1 h2 h3],[h1 h1; h2 h3])
Tips
verifyNotSameHandle
is a convenience method. For example,verifyNotSameHandle(testCase,actual,prohibited)
is functionally equivalent to the following code.
import matlab.unittest.constraints.IsSameHandleAs
testCase.verifyThat(actual,~IsSameHandleAs(prohibited))- 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, see matlab.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, see matlab.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.
- 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
Version History
Introduced in R2013a
In qualifications, character vectors are no longer equivalent to enumerations of a handle class. For example, consider this enumeration class.
classdef MyClass < handle enumeration X Y end end
This test passes because 'X'
does not represent the enumerationMyClass.X
. In previous releases, the test fails.
testCase = matlab.unittest.TestCase.forInteractiveUse; testCase.verifyNotSameHandle('X',MyClass.X)