matlab.unittest.diagnostics.StringDiagnostic class

Package: matlab.unittest.diagnostics
Superclasses: matlab.unittest.diagnostics.Diagnostic

Diagnostic using string

Description

The StringDiagnostic class provides a diagnostic result that uses a string. When the diagnostic information is known at the time of construction, the StringDiagnostic is a means to provide quick diagnostic information.

When using matlab.unittest qualifications, a string can be supplied directly as a test diagnostic. In this case, the testing framework automatically creates a StringDiagnostic object.

Construction

StringDiagnostic(diagString) creates a new StringDiagnostic instance.

Input Arguments

diagString

The string that the Diagnostic uses to generate diagnostic information.

Methods

Inherited Methods

diagnoseExecute diagnostic action
joinJoin multiple diagnostics into a single array

Copy Semantics

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

Examples

collapse all

Create a test case for interactive testing.

import matlab.unittest.TestCase
import matlab.unittest.constraints.IsEqualTo
import matlab.unittest.diagnostics.StringDiagnostic

testCase = TestCase.forInteractiveUse;

Use a StringDiagnostic to display diagnostic information upon test failure.

testCase.verifyThat(1, IsEqualTo(2), ...
    StringDiagnostic('actual was supposed to be equal to expected') )
Verification failed.
    ----------------
    Test Diagnostic:
    ----------------
    actual was supposed to be equal to expected
    ---------------------
    Framework Diagnostic:
    ---------------------
    IsEqualTo failed.
    --> NumericComparator failed.
        --> The numeric values are not equal using "isequaln".
        --> Failure table:
                Actual    Expected    Error    RelativeError
                ______    ________    _____    _____________
                  1          2         -1          -0.5     
        
        Actual Value:
             1
        Expected Value:
             2

Alternatively, the test framework can create a StringDiagnostic object for you from a string input to the verifyThat qualification.

testCase.verifyThat(1, IsEqualTo(2), ...
    'actual was supposed to be equal to expected' )
Verification failed.
    ----------------
    Test Diagnostic:
    ----------------
    actual was supposed to be equal to expected
    ---------------------
    Framework Diagnostic:
    ---------------------
    IsEqualTo failed.
    --> NumericComparator failed.
        --> The numeric values are not equal using "isequaln".
        --> Failure table:
                Actual    Expected    Error    RelativeError
                ______    ________    _____    _____________
                  1          2         -1          -0.5     
        
        Actual Value:
             1
        Expected Value:
             2

The testing framework only creates the StringDiagnostic object as needed, typically only in the event of a test failure.

Introduced in R2013a