Main Content

matlab.automation.diagnostics.DisplayDiagnostic Class

Namespace: matlab.automation.diagnostics
Superclasses: matlab.automation.diagnostics.Diagnostic

Diagnostic result using displayed output of value

Renamed from matlab.unittest.diagnostics.DisplayDiagnostic in R2023a

Description

The matlab.automation.diagnostics.DisplayDiagnostic class defines a diagnostic result that uses the displayed output of a value. If diagnostic information is available from a variable in the current workspace, use the DisplayDiagnostic class to display that diagnostic information.

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

Creation

Description

example

diag = matlab.automation.diagnostics.DisplayDiagnostic(value) creates a DisplayDiagnostic object and sets its Value property.

Properties

expand all

Diagnostic value used to generate diagnostic information, specified as a value of any data type.

The resulting diagnostic information is equivalent to displaying this value at the MATLAB® command prompt. The result is packaged for consumption by an automation framework, such as the unit testing framework.

Attributes:

GetAccess
public
SetAccess
immutable

Text used to generate diagnostic information, returned as a character vector. This property is defined during evaluation of the diagnose method.

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 the value of datetime when a test fails, so you can see the date and time of the test failure.

First, import the classes used in this example.

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

Create a test case for interactive testing.

testCase = TestCase.forInteractiveUse;

Display diagnostic information upon test failure by using a DisplayDiagnostic object. When the test fails, the DisplayDiagnostic object displays the value of datetime. The displayed value is the date and time that the test failed.

testCase.verifyThat(1,IsEqualTo(2),DisplayDiagnostic(datetime))
Verification failed.    
----------------
Test Diagnostic:
----------------
  datetime

   15-Oct-2022 20:08:00
---------------------
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

Version History

Introduced in R2013a

expand all