diagnose
执行诊断操作
说明
当诊断使用方(如单元测试框架)调用方法来计算诊断时,diagnose( 执行指定诊断的操作。diagnostic)
从 Diagnostic 类派生的类必须实现 diagnose 方法。当您为自定义诊断类实现此方法时,请在方法中设置 DiagnosticText 属性以使信息对诊断的使用方可用。
输入参数
诊断,指定为 matlab.automation.diagnostics.Diagnostic 对象。
示例
创建提供活动进程状态的自定义诊断。定义诊断的类必须从 matlab.automation.diagnostics.Diagnostic 派生,实现 diagnose 方法,并设置 DiagnosticText 属性。
在当前文件夹的名为 ProcessStatusDiagnostic.m 的文件中,通过子类化 matlab.automation.diagnostics.Diagnostic 来创建 ProcessStatusDiagnostic 类。将以下元素添加到类:
HeaderText属性 - 添加此属性以在诊断构造过程中自定义诊断文本。ProcessStatusDiagnostic方法 - 实现此构造函数方法以设置HeaderText属性。diagnose方法 - 实现此方法以编码诊断操作。访问进程状态信息,并使用此信息设置DiagnosticText属性。
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
创建一个供交互测试的测试用例。
testCase = matlab.unittest.TestCase.forInteractiveUse;
要在测试失败时显示自定义诊断信息,请将 ProcessStatusDiagnostic 对象传递给您的鉴定方法。
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创建 ProcessStatusDiagnostic 对象时,通过指定可选输入来自定义诊断文本。
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版本历史记录
在 R2013a 中推出
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)