Main Content

matlab.unittest.diagnostics.FunctionHandleDiagnostic class

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

Diagnostic result using displayed output of function

Description

The matlab.unittest.diagnostics.FunctionHandleDiagnostic class defines a diagnostic result using the displayed output of a function. This output is the same as the text displayed at the command prompt when MATLAB® runs the function. If diagnostic information is available from the displayed output of a function, use the FunctionHandleDiagnostic class to display that diagnostic information.

When using qualification methods such as verifyThat, you can specify the test diagnostic directly as a function handle. In this case, the testing framework automatically constructs a FunctionHandleDiagnostic object and associates it with the specified function handle.

The matlab.unittest.diagnostics.FunctionHandleDiagnostic class is a handle class.

Creation

Description

example

diag = matlab.unittest.diagnostics.FunctionHandleDiagnostic(fcn) creates a FunctionHandleDiagnostic object and sets its Fcn property.

Properties

expand all

Function handle used to generate diagnostic information, returned as a function_handle object.

The resulting diagnostic information is equivalent to output displayed 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
private

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 output of the dir command when a test fails.

First, create a subfolder in your current folder.

mkdir("subfolderInCurrentFolder")

Import the classes used in this example.

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

Create a test case for interactive testing.

testCase = TestCase.forInteractiveUse;

Display diagnostic information upon test failure by using a FunctionHandleDiagnostic object. When the test fails, the FunctionHandleDiagnostic object displays the contents of the current folder, which in this case, is the subfolderInCurrentFolder folder.

testCase.verifyThat(1,IsEqualTo(2),FunctionHandleDiagnostic(@dir))
Verification failed.

----------------
Test Diagnostic:
----------------

.                         ..                        subfolderInCurrentFolder  



---------------------
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 FunctionHandleDiagnostic object for you from a function handle input to the verifyThat method.

testCase.verifyThat(1,IsEqualTo(2),@dir)
Verification failed.

----------------
Test Diagnostic:
----------------

.                         ..                        subfolderInCurrentFolder  



---------------------
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 FunctionHandleDiagnostic object as needed, typically only in the event of a test failure.

Version History

Introduced in R2013a