Main Content

matlab.unittest.diagnostics.Diagnostic class

Package:matlab.unittest.diagnostics

Fundamental interface class formatlab.unittestdiagnostics

Description

TheDiagnosticinterface class is the means by which thematlab.unittestframework and its clients package diagnostic information. All diagnostics are derived fromDiagnostic, whether they are user-supplied test diagnostics for an individual comparison or diagnostics associated with theConstraintused in the comparison.

Classes which derive fromDiagnosticencode the diagnostic actions to be performed. They produce a diagnostic result that is displayed appropriately by the test running framework. In exchange for meeting this requirement, anyDiagnosticimplementation can be used directly withmatlab.unittestqualifications. These qualifications execute the diagnostic action and store the result for the test running framework to use.

方便,框架创建appropriate diagnostic instances for arrays of character vectors, strings, and function handles when they are user supplied test diagnostics. To retain good performance, these values are only converted intoDiagnosticinstances when a qualification failure occurs or when the test running framework is explicitly observing passing qualifications. The default test runner does not explicitly observe passing qualifications.

Properties

Artifacts

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

DiagnosticText

TheDiagnosticTextproperty 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 thediagnosemethod.

Methods

diagnose Execute diagnostic action
join Join multiple diagnostics into a single array

Copy Semantics

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

Examples

collapse all

importmatlab.unittest.constraints.IsEqualTo% Create a TestCase for interactive usetestCase = matlab.unittest.TestCase.forInteractiveUse;% Create StringDiagnostic upon failuretestCase.verifyThat(1, IsEqualTo(2),'User supplied Diagnostic')% Create FunctionHandleDiagnostic upon failuretestCase.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%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%classdefProcessStatusDiagnostic < matlab.unittest.diagnostics.Diagnostic% ProcessStatusDiagnostic - an example diagnostic%% Simple example to demonstrate how to create a custom% diagnostic.properties% HeaderText - user-supplied header to displayHeaderText ='(No header supplied)';endmethodsfunctiondiag = 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;endendfunctiondiagnose(diag) [status, processInfo] = system('ps');if(status ~= 0) processInfo = sprintf(...['!!! Could not obtain status diagnostic information!!!'...' [exit status code: %d]\n%s'], status, processInfo);enddiag.DiagnosticText = sprintf('%s\n%s', diag.HeaderText,...processInfo);endendend% classdef