Main Content

matlab.unittest.qualifications.Verifiable Class

Namespace: 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 qualification classes in the matlab.unittest.qualifications namespace.

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 exception. This behavior 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 qualification type within a Four-Phase Test. Use other qualification types, such as assumptions, assertions, and fatal assertions to test for violation of preconditions or incorrect test setup.

Because verifications do not throw an exception, all test content runs to completion even when the test fails. This behavior 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, because 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, if you overuse verifications, they can produce excess noise for a single failure. If a failure will cause later qualification points to also fail, use assertions or fatal assertions instead.

The matlab.unittest.qualifications.Verifiable class is a handle class.


expand all


Event NameTriggerEvent DataEvent Attributes
VerificationFailedTriggered upon failing verification. A QualificationEventData object is passed to listener callback functions.matlab.unittest.qualifications.QualificationEventData

NotifyAccess: private

ListenAccess: public

VerificationPassedTriggered upon passing verification. A QualificationEventData object is passed to listener callback functions.matlab.unittest.qualifications.QualificationEventData

NotifyAccess: private

ListenAccess: public


collapse all

Use verifications to test the DocPolynom class, which represents polynomials in MATLAB®. For more information about the class and to view the class code, see Representing Polynomials with Classes.

In a file named DocPolynom.m in your current folder, create the DocPolynom class. To test different methods of the DocPolynom class, create the DocPolynomTest class in another file named DocPolynomTest.m in your current folder. Define three Test methods in the DocPolynomTest class:

  • testConstructor method — Use verifyClass to test the DocPolynom class constructor.

  • testAddition method — Use verifyEqual to test the addition of DocPolynom objects.

  • testMultiplication method — Use verifyEqual to test the multiplication of DocPolynom objects.

classdef DocPolynomTest < matlab.unittest.TestCase
        TextToDisplay = "Equation under test: "

    methods (Test)
        function testConstructor(testCase)
            p = DocPolynom([1 0 1]);

        function testAddition(testCase)
            p1 = DocPolynom([1 0 1]);
            p2 = DocPolynom([5 2]);
            actual = p1 + p2;
            expected = DocPolynom([1 5 3]);
            diagnostic = [testCase.TextToDisplay ...
                "(x^2 + 1) + (5*x + 2) = x^2 + 5*x + 3"];

        function testMultiplication(testCase)
            p1 = DocPolynom([1 0 3]);
            p2 = DocPolynom([5 2]);
            actual = p1 * p2;
            expected = DocPolynom([5 2 15 6]);
            diagnostic = [testCase.TextToDisplay ...
                "(x^2 + 3) * (5*x + 2) = 5*x^3 + 2*x^2 + 15*x + 6"];

Run the tests in the DocPolynomTest class. In this example, all the tests pass.

Running DocPolynomTest
Done DocPolynomTest
ans = 
  1×3 TestResult array with properties:


   3 Passed, 0 Failed, 0 Incomplete.
   0.26915 seconds testing time.

Version History

Introduced in R2013a