matlab.unittest.qualifications.FatalAssertable class

Package: matlab.unittest.qualifications

Qualification to abort test execution


The FatalAssertable class provides a qualification to abort test execution. Apart from actions performed for failures, the FatalAssertable class works the same as matlab.unittest qualifications.

Upon a fatal assertion failure, the FatalAssertable class informs the testing framework of the failure by throwing a FatalAssertionFailedException. The test running framework then displays diagnostic information for the failure and aborts the entire test session. This is useful when the software under test contains so many errors that it does not make sense to continue the test session. Also, you can use fatal assertions in fixture teardown to guarantee the fixture state is restored correctly. If it is not restored, the full testing session will abort and indicate to restart MATLAB® before you resume testing. This allows later tests to run in a consistent MATLAB state. If you can recover the fixture teardown and make it Exception Safe for failures, use assertions instead.

Fatal assertions prevent false test failures due to the failure of a fundamental test. They also prevent false test failures when a prior test failed to restore test fixtures. If the test framework cannot properly tear down fixtures, restart MATLAB to ensure testing can resume in a clean state.


fatalAssertClassFatally assert exact class of specified value
fatalAssertEmptyFatally assert value is empty
fatalAssertEqualFatally assert value is equal to specified value
fatalAssertErrorFatally assert function throws specified exception
fatalAssertFailProduce unconditional fatal assertion failure
fatalAssertFalseFatally assert value is false
fatalAssertGreaterThanOrEqualFatally assert value is greater than or equal to specified value
fatalAssertInstanceOfFatally assert value is object of specified type
fatalAssertLengthFatally assert value has specified length
fatalAssertLessThanFatally assert value is less than specified value
fatalAssertLessThanOrEqualFatally assert value is less than or equal to specified value
fatalAssertMatchesFatally assert string matches specified regular expression
fatalAssertNotEmptyFatally assert value is not empty
fatalAssertNotEqualFatally assert value is not equal to specified value
fatalAssertNotSameHandleFatally assert value is not handle to specified instance
fatalAssertNumElementsFatally assert value has specified element count
fatalAssertReturnsTrueFatally assert function returns true when evaluated
fatalAssertSameHandleFatally assert two values are handles to same instance
fatalAssertSizeFatally assert value has specified size
fatalAssertSubstringFatally assert string contains specified string
fatalAssertThatFatally assert value meets specified constraint
fatalAssertTrueFatally assert value is true
fatalAssertWarningFatally assert function issues specified warnings
fatalAssertWarningFreeFatally assert function issues no warnings



Triggered upon failing fatal assertion. A QualificationEventData object is passed to listener callback functions.


Triggered upon passing fatal assertion. A QualificationEventData object is passed to listener callback functions.

Copy Semantics

Handle. To learn how handle classes affect copy operations, see Copying Objects.


collapse all

A fatal assertion renders the remainder of the current test method invalid because the state is unrecoverable. A helper function is a function in the TestCase class but not located within any of the methods block statement. Execution of these functions is not controlled by the matlab.unittest framework.

Add the DocPolynomSaveLoadTest.m file to a folder on your MATLAB path. Refer to the helper function, cleanUpTemporaryFolder, in the DocPolynomSaveLoadTest test case.

 DocPolynomSaveLoadTest Class Definition File

Make the cleanUpTemporaryFolder function a helper function by placing it inside a separate methods block.

    function cleanUpTemporaryFolder(testCase, tempFolder) 
        % code 

Use the fatalAssertTrue method to test the rmdir success argument for errors. If a fatal assertion occurs, the test run is aborted.

function cleanUpTemporaryFolder(testCase, tempFolder) 
    import matlab.unittest.diagnostics.Diagnostic
    [success, message] = rmdir(tempFolder, 's'); 
    testCase.fatalAssertTrue(success, ... 
        Diagnostic.join('Could not remove the temporary folder.',... 

If the rmdir function fails, then this test has failed to restore the state of MATLAB and the machine at initial startup. Aborting prevents subsequent tests to fail because MATLAB is left in an unexpected state by this test.

More About

expand all

Introduced in R2013a