matlab.unittest.diagnostics.DisplayDiagnostic class

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

Diagnostic using a value's displayed output

Description

The DisplayDiagnostic class provides a diagnostic result that uses a value's displayed output. This output is the same text displayed using the display function. When the diagnostic information is accessible through a variable in the current workspace, the DisplayDiagnostic class is a means to provide quick diagnostic information.

Construction

DisplayDiagnostic(diagValue) creates a new DisplayDiagnostic instance.

Input Arguments

diagValue

The value that the Diagnostic uses to generate diagnostic information.

The resulting diagnostic information is equivalent to displaying this value at the MATLAB® command prompt. The result is packaged for consumption by the testing framework, which may or may not display the information at the command prompt.

Properties

Value

The value that the Diagnostic uses to generate diagnostic information, specified in the diagValue input argument. This property is read-only.

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 DisplayDiagnostic Object

Create a test case for interactive testing.

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

testCase = TestCase.forInteractiveUse;

Use a DisplayDiagnostic to display diagnostic information upon test failure.

testCase.verifyThat(1, IsEqualTo(2), DisplayDiagnostic(inputParser))
Interactive verification failed.

----------------
Test Diagnostic:
----------------
      inputParser with properties:
    
           FunctionName: ''
          CaseSensitive: 0
          KeepUnmatched: 0
        PartialMatching: 1
           StructExpand: 1
             Parameters: {1x0 cell}
                Results: [1x1 struct]
              Unmatched: [1x1 struct]
          UsingDefaults: {1x0 cell}

---------------------
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

In the test diagnostic section of the output, the output from inputParser object is the same as MATLAB displays at the command prompt.

Was this topic helpful?