Qualification to filter test content
The Assumable class provides a qualification to filter test content. Apart from actions performed in the event of failures, the Assumable class works the same as other matlab.unittest qualifications.
Upon an assumption failure, the Assumable class informs the testing framework of the failure by throwing an AssumptionFailedException. The test framework then marks the test content as filtered and continues testing. Often, assumptions are used to ensure that the test is run only when certain preconditions are met. However, running the test without satisfying the preconditions does not produce a test failure. Ensure that the test content is Exception Safe. If the failure condition is meant to produce a test failure, use assertions or verifications instead of assumptions.
The attributes specified in the TestCase method definition determine which tests are filtered. The following behavior occurs when the test framework encounters an assumption failure inside of a TestCase method:
If you define the TestCase method using the Test attribute, the framework marks the entire method as filtered and runs subsequent test methods.
If you define the TestCase method using the TestMethodSetup or TestMethodTeardown attributes, the test framework marks the method to run for that instance as filtered.
If you define the TestCase method using the TestClassSetup or TestClassTeardown attributes, the test framework filters the entire TestCase class.
Filtering test content using assumptions does not produce test failures. Therefore, dead test code can result. Avoid this by monitoring filtered tests.
|assumeClass||Assume exact class of specified value|
|assumeEmpty||Assume value is empty|
|assumeEqual||Assume value is equal to specified value|
|assumeError||Assume function throws specified exception|
|assumeFail||Produce unconditional assumption failure|
|assumeFalse||Assume value is false|
|assumeGreaterThan||Assume value is greater than specified value|
|assumeGreaterThanOrEqual||Assume value is greater than or equal to specified value|
|assumeInstanceOf||Assume value is object of specified type|
|assumeLength||Assume value has specified length|
|assumeLessThan||Assume value is less than specified value|
|assumeLessThanOrEqual||Assume value is less than or equal to specified value|
|assumeMatches||Assume string matches specified regular expression|
|assumeNotEmpty||Assume value is not empty|
|assumeNotEqual||Assume value is not equal to specified value|
|assumeNotSameHandle||Assume value is not handle to specified instance|
|assumeNumElements||Assume value has specified element count|
|assumeReturnsTrue||Assume function returns true when evaluated|
|assumeSameHandle||Assume two values are handles to same instance|
|assumeSize||Assume value has specified size|
|assumeSubstring||Assume string contains specified string|
|assumeThat||Assume value meets specified constraint|
|assumeTrue||Assume value is true|
|assumeWarning||Assume function issues specified warning|
|assumeWarningFree||Assume function issues no warnings|
Test content is exception safe when all fixture teardown is performed with addTeardown or through the appropriate object destructors when a failure occurs. This ensures that the failure does not affect later testing due to stale fixtures.
This code is not exception safe. After an assertion failure, the test framework does not close the figure.
% Not exception safe f = figure; testCase.assertEqual(actual, expected); close(f);
This code is exception safe because the test framework closes the figure in all cases.
% Exception safe f = figure; testCase.addTeardown(@close, f); testCase.assertEqual(actual, expected);
However, tearing down a fixture using addTeardown does not guarantee code is exception safe. This code shows a failure in assertEqual.
% Not exception safe f = figure; testCase.assertEqual(actual, expected); testCase.addTeardown(@close, f);
Handle. To learn how handle classes affect copy operations, see Copying Objects in the MATLAB® documentation.