Main Content

matlab.unittest.qualifications.Verifiable class

Package: matlab.unittest.qualifications

Qualification to produce soft failure conditions


The Verifiable class provides a qualification to produce soft-failure conditions. Apart from actions performed for failures, the Verifiable class works the same as other matlab.unittest qualifications.

Upon a verification failure, the Verifiable class informs the testing framework of the failure, including all diagnostic information associated with the failure, but continues to execute the currently running test without throwing an MException. This is most useful when a failure at the verification point is not fatal to the remaining test content. Often, you use verifications as the primary verification of a Four-Phase Test. Use other qualification types, such as assertions, fatal assertions, and assumptions, to test for violation of preconditions or incorrect test setup.

Since verifications do not throw MExceptions, all test content runs to completion even when verification failures occur. This helps you understand how close a piece of software is to meeting the test suite requirements. Qualification types that throw exceptions do not provide this insight, since once an exception is thrown an arbitrary amount of code remains that is not reached or exercised. Verifications also provide more testing coverage in failure conditions. However, when you overuse verifications, they can produce excess noise for a single failure condition. If a failure condition will cause later qualification points to also fail, use assertions or fatal assertions instead.


verifyClassVerify exact class of specified value
verifyEmptyVerify value is empty
verifyEqualVerify value is equal to specified value
verifyErrorVerify function throws specified exception
verifyFailProduce unconditional verification failure
verifyFalseVerify value is false
verifyGreaterThanVerify value is greater than specified value
verifyGreaterThanOrEqualVerify value is greater than or equal to specified value
verifyInstanceOfVerify value is object of specified type
verifyLengthVerify value has specified length
verifyLessThanVerify value is less than specified value
verifyLessThanOrEqualVerify value is less than or equal to specified value
verifyMatchesVerify string matches specified regular expression
verifyNotEmptyVerify value is not empty
verifyNotEqualVerify value is not equal to specified value
verifyNotSameHandleVerify value is not handle to specified instance
verifyNumElementsVerify value has specified element count
verifyReturnsTrueVerify function returns true when evaluated
verifySameHandleVerify two values are handles to same instance
verifySizeVerify value has specified size
verifySubstringVerify string contains specified string
verifyThatVerify value meets given constraint
verifyTrueVerify value is true
verifyWarningVerify function issues specified warnings
verifyWarningFreeVerify function issues no warnings



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


Triggered upon passing verification. 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

Verifications produce and record failures without throwing an exception, meaning the currently running test runs to completion. This example creates a test case to verify arithmetic operations on objects of the DocPolynom example class.

Create the DocPolynomTest Test Case. Refer to the following DocPolynomTest test case in the subsequent steps in this example, which highlight specific functions in the file.

 DocPolynomTest Class Definition File

To execute the MATLAB® commands in this example, add the DocPolynomTest.m file to a folder on your MATLAB path.

Write Test to Verify Constructor. Create a function, testConstructor, using the verifyClass method to test the DocPolynom class constructor.

function testConstructor(testCase)
    p = DocPolynom([1, 0, 1]);
    testCase.verifyClass(p, ?DocPolynom)

Write Tests to Verify Operations. In the testAddition function, use the verifyEqual method to test the equation (x^2 + 1) + (5*x + 2) = x^2 + 5*x + 3. The verifyEqual method includes this equation in the diagnostic argument.

function testAddition(testCase)
    p1 = DocPolynom([1, 0, 1]);
    p2 = DocPolynom([5, 2]);
    actual = p1 + p2;
    expected = DocPolynom([1, 5, 3]);
    msg = [testCase.msgEqn,...
        '(x^2 + 1) + (5*x + 2) = x^2 + 5*x + 3'];
    testCase.verifyEqual(actual, expected, msg)

The function, testMultiplication, tests multiplication operations.

Run the tests in the DocPolynomTest test case.

tc = DocPolynomTest;
ts = matlab.unittest.TestSuite.fromClass(?DocPolynomTest);
res = run(ts);
Running DocPolynomTest
Done DocPolynomTest

All tests passed.

Introduced in R2013a