matlab.automation.diagnostics.Diagnostic.diagnose - Perform diagnostic actions - MATLAB (original) (raw)
Main Content
Class: matlab.automation.diagnostics.Diagnostic
Namespace: matlab.automation.diagnostics
Perform diagnostic actions
Syntax
Description
diagnose([diagnostic](#mw%5F8d11856a-6dd8-42dd-9a7c-aa706e6a700c))
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 thediagnose
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
Diagnostic, specified as a matlab.automation.diagnostics.Diagnostic
object.
Examples
Create a custom diagnostic that provides the status of the active processes. Classes that define diagnostics must derive frommatlab.automation.diagnostics.Diagnostic
, implement thediagnose
method, and set the DiagnosticText
property.
In a file named ProcessStatusDiagnostic.m
in your current folder, create the ProcessStatusDiagnostic
class by subclassingmatlab.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 theHeaderText
property.diagnose
method — Implement this method to encode the diagnostic actions. Access the process status information and use this information to set theDiagnosticText
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 aProcessStatusDiagnostic
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 aProcessStatusDiagnostic
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