Main Content

matlab.unittest.diagnostics.DisplayDiagnostic class

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

Diagnostic result using displayed output of value

Description

The matlab.unittest.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.unittest.diagnostics.DisplayDiagnostic class is a handle class.

Creation

Description

example

diag = matlab.unittest.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 the testing framework, which may or may not display the information at the command prompt.

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

Methods

expand all

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

   03-Mar-2022 11:23:58
---------------------
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