This example shows how to use matlab.unittest.TestCase assumable qualifications in a TestClassSetup method.
Assumptions assure that a test runs only when certain preconditions are satisfied and when such an event should not produce a test failure. When an assumption failure occurs, the test is marked as filtered.
|On this page…|
IsSupportedTest Test Case
Refer to the following IsSupportedTest test case in the subsequent steps in this example, which highlight specific functions in the file.
To execute the MATLAB® commands in this example, add the IsSupportedTest.m file to a folder on your MATLAB path.
Write Test to Verify Platform
All tests in this test case must run on UNIX® platforms only. The TestPlatform function uses the assumeFalse method to test if MATLAB is running on a Windows® platform. If it is, the test fails.
function TestPlatform(testcase) testcase.assumeFalse(ispc,... 'Do not run any of these tests on Windows.'); end
Make TestPlatform a TestClassSetup Test
To make the TestPlatform test a precondition, add it inside the methods (TestClassSetup) block.
Run Test Case
Create a test case object and run the tests on a Windows platform.
tc = IsSupportedTest; res = tc.run;
Running IsSupportedTest ================================================================================ All tests in IsSupportedTest were filtered. Test Diagnostic: Do not run any of these tests on Windows. Details ================================================================================ Done IsSupportedTest __________ Failure Summary: Name Failed Incomplete Reason(s) ==================================================================== IsSupportedTest/test1 X Filtered by assumption.
The test(s) were filtered, and did not run (marked Incomplete).
Get Information About Failure
For more information, click the Details link.
================================================================================ The TestClassSetup or TestClassTeardown for IsSupportedTest was filtered by an assumption. All tests in this class were also filtered as a result. ---------------- Test Diagnostic: ---------------- Do not run any of these tests on Windows. --------------------- Framework Diagnostic: --------------------- assumeFalse failed. --> The value must evaluate to "false". Actual Value: 1 ------------------ Stack Information: ------------------ In C:\Program Files\MATLAB\R2013a\toolbox\matlab\testframework\+matlab\+unittest\+qualifications\Assumable.m (Assumable.assumeFalse) at 331 In c:\work\IsSupportedTest.m (IsSupportedTest.TestPlatform) at 4 ================================================================================
The link to IsSupportedTest.TestPlatform under Stack Information takes you to the failed assumeFalse method.