Main Content

matlab.automation.diagnostics.Diagnostic class

Package: matlab.automation.diagnostics

Fundamental interface class for diagnostics (renamed from matlab.unittest.diagnostics.Diagnostic)


The matlab.automation.diagnostics.Diagnostic class provides an interface that you can use to package diagnostic information. All diagnostics are derived from the Diagnostic interface, whether they are user-supplied diagnostics or framework diagnostics. Classes that derive from Diagnostic encode the diagnostic actions to be performed and produce a diagnostic result that can be used by an automation framework, for example, the unit testing framework, and displayed as appropriate for that framework.

When used with the testing framework, any Diagnostic implementation can be used directly with matlab.unittest qualifications, which execute the diagnostic actions and store the result to be used by the framework. As a convenience, the framework creates appropriate Diagnostic instances for user-supplied diagnostics that are arrays of character vectors, strings, and function handles. To retain good performance, these values are converted to Diagnostic instances only when a qualification failure occurs or when the framework explicitly observes passing qualifications. The default test runner does not explicitly observe passing qualifications.



The artifacts produced during the last diagnostic evaluation, returned as an array of artifacts.


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.


diagnoseExecute diagnostic action
joinJoin multiple diagnostics into a single array

Copy Semantics

Handle. To learn how handle classes affect copy operations, see Copying Objects.


collapse all

import matlab.unittest.constraints.IsEqualTo

% Create a TestCase for interactive use
testCase = matlab.unittest.TestCase.forInteractiveUse;

% Create StringDiagnostic upon failure
testCase.verifyThat(1, IsEqualTo(2), 'User supplied Diagnostic')

% Create FunctionHandleDiagnostic upon failure
testCase.verifyThat(1, IsEqualTo(2), @() system('ps'))

% Usage of user defined Diagnostic upon failure (see definition below)
testCase.verifyThat(1, IsEqualTo(2), ProcessStatusDiagnostic...
    ('Could not close my third party application!'))

% Diagnostic definition
classdef ProcessStatusDiagnostic < matlab.automation.diagnostics.Diagnostic
    % ProcessStatusDiagnostic - an example diagnostic
    %   Simple example to demonstrate how to create a custom
    %   diagnostic.
        % HeaderText - user-supplied header to display
        HeaderText = '(No header supplied)';
        function diag = ProcessStatusDiagnostic(header)
            % Constructor - construct a ProcessStatusDiagnostic
            %   The ProcessStatusDiagnostic constructor takes an
            %   optional header to be displayed along with process
            %   information.
            if (nargin >0)
                diag.HeaderText = header;
        function diagnose(diag)
            [status, processInfo] = system('ps');
            if (status ~= 0)
                processInfo = sprintf(...
                    ['!!! Could not obtain status diagnostic information!!!'...
                    ' [exit status code: %d]\n%s'], status, processInfo);
            diag.DiagnosticText = sprintf('%s\n%s', diag.HeaderText,...
end % classdef

Version History

Introduced in R2013a

expand all