Main Content


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

Perform diagnostic actions



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.

Input Arguments

expand all

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



To learn about attributes of methods, see Method Attributes.


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)

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

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

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.

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