matlab.unittest.diagnostics.FunctionHandleDiagnostic class

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

Diagnostic using a function's displayed output

Description

The FunctionHandleDiagnostic class provides a diagnostic result using a function’s displayed output. This output is the same as the text displayed at the command prompt when MATLAB® executes the function handle. When the diagnostic information is accessible through information displayed as output of the function handle, the FunctionHandleDiagnostic is a means to provide quick diagnostic information.

When using matlab.unittest qualifications, a function handle can be supplied directly as a test diagnostic. In this case, the testing framework automatically creates a FunctionHandleDiagnostic object.

Construction

FunctionHandleDiagnostic(fcnHandle) creates a new FunctionHandleDiagnostic instance.

Input Arguments

fcnHandle

The function handle that the Diagnostic uses to generate diagnostic information.

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.

Properties

Fcn

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

Inherited Properties

DiagnosticText

The DiagnosticText property provides the means by which the actual diagnostic information is communicated to consumers of diagnostics, such as testing frameworks. The property is a character vector 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.

Examples

collapse all

Create a diagnostic result that displays the output of the dir function when a test fails.

Create a folder in your current working folder.

mkdir('subfolderInCurrentFolder')

Create a test case for interactive testing.

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

testCase = TestCase.forInteractiveUse;

Use a FunctionHandleDiagnostic to display diagnostic information upon test failure.

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 double:
         1
Expected double:
         2

Upon test failure, the diagnostic displays the contents of the current working folder. In this example output, the folder only contains the subfolder subfolderInCurrentFolder.

Alternatively, the test framework can create a FunctionHandleDiagnostic object for you from a function handle input to the verifyThat qualification.

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 double:
         1
Expected double:
         2

The testing framework only creates the FunctionHandleDiagnostic object as needed, typically only in the event of a test failure.

Introduced in R2013a