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.

Properties

Inherited Properties

DiagnosticResult

The DiagnosticResult property provides the means by which the actual diagnostic information is communicated to consumers of diagnostics, such as testing frameworks. The property is a string that is defined during evaluation of the diagnose method.

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 in the MATLAB® documentation.

Examples

expand all

Create StringDiagnostic Object

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') )
Interactive verification failed.

----------------
Test Diagnostic:
----------------
actual was supposed to be equal to expected

---------------------
Framework Diagnostic:
---------------------
IsEqualTo failed.
--> NumericComparator failed.
    --> The values are not equal using "isequaln".
    --> Failure table:
                Index    Actual    Expected    Error    RelativeError
                _____    ______    ________    _____    _____________
            
                1        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' )
Interactive verification failed.

----------------
Test Diagnostic:
----------------
actual was supposed to be equal to expected

---------------------
Framework Diagnostic:
---------------------
IsEqualTo failed.
--> NumericComparator failed.
    --> The values are not equal using "isequaln".
    --> Failure table:
                Index    Actual    Expected    Error    RelativeError
                _____    ______    ________    _____    _____________
            
                1        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.

Was this topic helpful?