Main Content

matlab.automation.diagnostics.StringDiagnostic class

Package: matlab.automation.diagnostics
Superclasses: matlab.automation.diagnostics.Diagnostic

Diagnostic result using string

Renamed from matlab.unittest.diagnostics.StringDiagnostic in R2023a

Description

The matlab.automation.diagnostics.StringDiagnostic class defines a diagnostic result that uses a string. If diagnostic information is known at the time of construction, use the StringDiagnostic class to display that diagnostic information.

When using qualification methods such as verifyThat, you can specify the test diagnostic directly as a string. In this case, the testing framework automatically constructs a StringDiagnostic object.

The matlab.automation.diagnostics.StringDiagnostic class is a handle class.

Creation

Description

example

diag = matlab.automation.diagnostics.StringDiagnostic(diagnosticText) creates a StringDiagnostic object and sets its DiagnosticText property.

Properties

expand all

Text used to generate diagnostic information, specified as a character vector or string array and stored as a character vector.

The DiagnosticText property provides the means by which the actual diagnostic information is communicated to consumers of diagnostics, such as testing frameworks.

Attributes:

GetAccess
public
SetAccess
protected

Examples

collapse all

Create a diagnostic result that displays a string when a test fails.

First, import the classes used in this example.

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

Create a test case for interactive testing.

testCase = TestCase.forInteractiveUse;

Display diagnostic information upon test failure by using a StringDiagnostic object. When the test fails, the StringDiagnostic object displays the specified string.

testCase.verifyThat(1,IsEqualTo(2), ...
    StringDiagnostic("Actual must be equal to expected."))
Verification failed.
    ----------------
    Test Diagnostic:
    ----------------
    Actual must 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 testing framework can create a StringDiagnostic object for you from a string input to the verifyThat method.

testCase.verifyThat(1,IsEqualTo(2), ...
    "Actual must be equal to expected.")
Verification failed.
    ----------------
    Test Diagnostic:
    ----------------
    Actual must 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 constructs the StringDiagnostic object as needed, typically only in the event of a test failure.

Version History

Introduced in R2013a

expand all