matlab.automation.diagnostics.Diagnostic - Fundamental interface for diagnostics - MATLAB (original) (raw)
Main Content
Namespace: matlab.automation.diagnostics
Fundamental interface for diagnostics
Renamed from matlab.unittest.diagnostics.Diagnostic
in R2023a
Description
The matlab.automation.diagnostics.Diagnostic
class provides an interface that you can use to package diagnostic information. All diagnostics are derived from theDiagnostic
class, whether they are user-supplied diagnostics or framework diagnostics. Diagnostic
subclasses encode the diagnostic actions to be performed and produce a diagnostic result that can be used by an automation framework, such as the unit testing framework, and displayed as appropriate for that framework.
To create a custom diagnostic class:
- Derive your class from
matlab.automation.diagnostics.Diagnostic
. - Implement the diagnose method to encode the diagnostic actions to be performed.
- Set the
[DiagnosticText](matlab.automation.diagnostics.diagnostic-class.html#mw%5F9a2785f9-c1b4-4fbd-81f8-ebabe6acb4f5)
property within thediagnose
method to make information available to consumers of the diagnostic.
When used with the testing framework, any Diagnostic
implementation can be used directly with the matlab.unittest.qualifications qualification methods, which perform 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 string arrays, character arrays, or function handles. To retain good performance, the framework converts these values toDiagnostic
instances only when needed, typically in the event of a test failure.
The matlab.automation.diagnostics.Diagnostic
class is a handle class.
Properties
Artifacts produced during the latest diagnostic evaluation, returned as a row vector of artifacts. The data type of the artifacts depends on the diagnostic evaluation. For example, if the diagnostic evaluation results in capturing screenshots, the property contains the screenshots as a row vector of matlab.automation.diagnostics.FileArtifact objects.
Attributes:
GetAccess | public |
---|---|
SetAccess | Restricts access |
Text used to communicate diagnostic information, returned as a character vector. Set this property within the diagnose method in your custom diagnostic class implementation.
The DiagnosticText
property makes information available to consumers of diagnostics, such as testing frameworks.
Attributes:
GetAccess | public |
---|---|
SetAccess | protected |
Methods
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
To reflect support for additional automated workflows,matlab.unittest.diagnostics.Diagnostic
is now namedmatlab.automation.diagnostics.Diagnostic
. The behavior of this class remains the same, and existing instances ofmatlab.unittest.diagnostics.Diagnostic
in your code continue to work as expected. There are no plans to remove support for existing instances ofmatlab.unittest.diagnostics.Diagnostic
.
See Also
Classes
- matlab.unittest.plugins.DiagnosticsOutputPlugin | matlab.unittest.plugins.DiagnosticsValidationPlugin | matlab.unittest.plugins.DiagnosticsRecordingPlugin