Main Content

diagnose

Class: matlab.automation.diagnostics.Diagnostic
Namespace: matlab.automation.diagnostics

Perform diagnostic actions

Description

diagnose(diagnostic) performs the actions of the specified diagnostic when a diagnostic consumer, such as the unit testing framework, calls the method to evaluate the diagnostic.

Classes deriving from the Diagnostic class must implement the diagnose method. When you implement this method for a custom diagnostic class, set the DiagnosticText property within the method to make information available to consumers of the diagnostic.

example

Input Arguments

expand all

Diagnostic, specified as a matlab.automation.diagnostics.Diagnostic object.

Attributes

Abstracttrue

To learn about attributes of methods, see Method Attributes.

Examples

expand all

Create a custom diagnostic that provides the status of the active processes. Classes that define diagnostics must derive from matlab.automation.diagnostics.Diagnostic, implement the diagnose method, and set the DiagnosticText property.

In a file named ProcessStatusDiagnostic.m in your current folder, create the ProcessStatusDiagnostic class by subclassing matlab.automation.diagnostics.Diagnostic. Add these elements to the class:

  • HeaderText property — Add this property to customize the diagnostic text during diagnostic construction.

  • ProcessStatusDiagnostic method — Implement this constructor method to set the HeaderText property.

  • diagnose method — Implement this method to encode the diagnostic actions. Access the process status information and use this information to set the DiagnosticText property.

classdef ProcessStatusDiagnostic < matlab.automation.diagnostics.Diagnostic
    properties (SetAccess=immutable)
        HeaderText
    end

    methods
        function diagnostic = ProcessStatusDiagnostic(header)
            arguments
                header (1,1) string = "Process Status Information"
            end
            diagnostic.HeaderText = header;
        end

        function diagnose(diagnostic)
            [~,processInfo] = system("ps");
            diagnostic.DiagnosticText = diagnostic.HeaderText + ...
                newline + processInfo;
        end
    end
end

Create a test case for interactive testing.

testCase = matlab.unittest.TestCase.forInteractiveUse;

To display custom diagnostic information when a test fails, pass a ProcessStatusDiagnostic object to your qualification method.

testCase.verifyFail(ProcessStatusDiagnostic)
Verification failed.
    ----------------
    Test Diagnostic:
    ----------------
    Process Status Information
          PID    PPID    PGID     WINPID   TTY         UID    STIME COMMAND
        22488       1   22488      22488  ?        2964717 10:24:31 /usr/bin/ps

Customize the diagnostic text by specifying the optional input when you create a ProcessStatusDiagnostic object.

testCase.verifyFail(ProcessStatusDiagnostic("Status of Active Processes"))
Verification failed.
    ----------------
    Test Diagnostic:
    ----------------
    Status of Active Processes
          PID    PPID    PGID     WINPID   TTY         UID    STIME COMMAND
        22828       1   22828      22828  ?        2964717 10:24:53 /usr/bin/ps

Version History

Introduced in R2013a