matlab.unittest.plugins.DiagnosticsOutputPlugin 类
包: matlab.unittest.plugins
用于将诊断信息定向到输出流的插件
描述
DiagnosticsOutputPlugin
类创建一个插件,用于将诊断信息定向到输出流。要配置测试框架输出的诊断类型和详细信息级别,请将此插件添加到 TestRunner
实例。
构造
matlab.unittest.plugins.DiagnosticsOutputPlugin
创建一个插件,用于将失败事件和在 Verbosity.Terse
级别记录的事件的诊断信息定向到 ToStandardOutput
流。
matlab.unittest.plugins.DiagnosticsOutputPlugin(
将诊断信息重定向到指定的输出流。例如,您可以将输出重定向到使用 stream
)ToFile
创建的流。
matlab.unittest.plugins.DiagnosticsOutputPlugin(___,
创建一个插件,并通过一个或多个 Name,Value
)Name,Value
对组参量指定其他选项。例如,DiagnosticsOutputPlugin('LoggingLevel',4,'IncludingPassingDiagnostics',true)
创建一个插件,显示在任何级别记录的诊断,并显示通过事件诊断信息。
输入参量
stream
— 输出位置
ToStandardOutput
(默认) | matlab.automation.streams.OutputStream
的实例
输出位置,指定为 OutputStream
类的实例。该插件将诊断信息定向到指定位置。默认情况下,插件使用 matlab.automation.streams.ToStandardOutput
流。
示例: matlab.automation.streams.ToFile('myFile.txt')
将可选的参量对组指定为 Name1=Value1,...,NameN=ValueN
,其中 Name
是参量名称,Value
是对应的值。名称-值参量必须出现在其他参量之后,但参量对组的顺序无关紧要。
在 R2021a 之前,使用逗号分隔每个名称和值,并用引号将 Name
引起来。
示例: DiagnosticsOutputPlugin('IncludingPassingDiagnostics',true,'OutputDetail',4)
创建一个插件,其中包括通过事件诊断信息并在“详尽”详细信息级别显示诊断信息。
ExcludingFailureDiagnostics
— 排除来自失败事件的诊断信息
false (默认) | true
是否排除来自失败事件的诊断信息,指定为 false
或 true
。默认情况下,该插件包含来自失败事件的诊断信息。
数据类型: logical
IncludingPassingDiagnostics
— 包含通过事件诊断信息
false
(默认) | true
是否包含通过事件的诊断信息,指定为 false
或 true
。默认情况下,该插件不包含来自通过事件的诊断信息。
数据类型: logical
LoggingLevel
— 记录的诊断的最大详细级别
1
(默认) | 0
| 2
| 3
| 4
| matlab.automation.Verbosity
枚举对象 | 枚举的文本表示
要在测试报告中包含的已记录诊断的最大详细级别,指定为从 0
到 4
的整数标量、matlab.automation.Verbosity
枚举对象或枚举的文本表示。插件包括在指定级别及更低级别记录的诊断。
数值表示 | 枚举成员名称 | 详细程度描述 |
---|---|---|
0 | None | 无信息 |
1 | Terse | 最少的信息 |
2 | Concise | 适中信息量 |
3 | Detailed | 部分补充信息 |
4 | Verbose | 大量补充信息 |
默认情况下,插件包含在 matlab.automation.Verbosity.Terse
级别(级别 1)记录的诊断信息。要排除所记录的诊断信息,请将 LoggingLevel
指定为 matlab.automation.Verbosity.None
(级别 0)。
记录的诊断是您使用 log (TestCase)
和 log (Fixture)
方法为测试框架提供的诊断。
示例: "LoggingLevel","detailed"
OutputDetail
— 报告事件的详细信息级别
3 (默认) | 0 | 1 | 2 | 4 | matlab.automation.Verbosity
枚举 | 枚举名称作为字符串或字符向量
报告事件的详细信息级别,指定为介于 0 和 4 之间的整数值、matlab.automation.Verbosity
枚举对象,或对应于预定义枚举成员名称之一的字符串标量或字符向量。整数值对应于 matlab.automation.Verbosity
枚举的成员。
该插件使用 OutputDetail
指定的信息量来报告通过事件、失败事件和日志记录事件。默认情况下,该插件在 matlab.automation.Verbosity.Detailed
级别(级别 3)记录事件。
数值表示 | 枚举成员名称 | 详细程度描述 |
---|---|---|
0 | None | 无信息 |
1 | Terse | 最少的信息 |
2 | Concise | 适中信息量 |
3 | Detailed | 部分补充信息 |
4 | Verbose | 大量补充信息 |
属性
ExcludeFailureDiagnostics
— 表明是否排除失败事件的诊断信息的指示符
false
(默认) | true
此 属性 为只读。
表明是否排除失败事件的诊断信息的指示符,指定为 false
或 true
(logical
0 或 1)。默认情况下,ExcludeFailureDiagnostics
为 false
,输出中包含来自失败事件的诊断信息。要从输出中排除失败事件的诊断信息,请在插件构造期间将 ExcludeFailureDiagnostics
指定为 true
。
IncludePassingDiagnostics
— 表明是否包含通过事件的诊断信息的指示符
false
(默认) | true
此 属性 为只读。
表明是否包含通过事件的诊断信息的指示符,指定为 false
或 true
(logical
0 或 1)。默认情况下,IncludePassingDiagnostics
为 false
,即不在输出中包含通过事件的诊断信息。要在输出中包含通过事件的诊断信息,请在构造插件时将 IncludePassingDiagnostics
指定为 true
。
LoggingLevel
— 插件包含的记录诊断信息的最高详细级别
matlab.automation.Verbosity.Terse
(默认) | matlab.automation.Verbosity
枚举对象
此 属性 为只读。
插件包含的记录诊断信息的最高详细级别,以 matlab.automation.Verbosity
枚举对象形式返回。该插件包含在此级别和更低级别记录的诊断信息。默认情况下,此属性值为 matlab.automation.Verbosity.Terse
。您可以在插件构造期间指定不同的日志记录级别。
记录的诊断信息是您通过调用 log (TestCase)
或 log (Fixture)
方法提供给测试框架的诊断信息。
OutputDetail
— 报告事件的详细信息级别
Detailed
(默认) | matlab.automation.Verbosity
实例
此 属性 为只读。
报告事件的详细信息级别,以 matlab.automation.Verbosity
枚举对象形式返回。默认情况下,此属性值为 matlab.automation.Verbosity.Detailed
。您可以在插件构造期间指定不同的输出详细信息级别。
复制语义
句柄。要了解句柄类如何影响复制操作,请参阅复制对象。
示例
创建插件以自定义诊断信息显示
创建文件 ExampleDiagOutputTest.m
,其中包含以下测试类。
classdef ExampleDiagOutputTest < matlab.unittest.TestCase methods(Test) function testOne(testCase) import matlab.automation.Verbosity testCase.log(Verbosity.Detailed,'Testing failing event') testCase.verifyEqual(42,13,'42 == 13') end function testTwo(testCase) testCase.log(3,'Testing passing event') testCase.verifyTrue(true,'true is true') end end end
根据 ExampleDiagOutputTest
类创建一个测试套件。创建一个不含任何插件的测试运行器。
import matlab.unittest.TestRunner import matlab.unittest.TestSuite import matlab.automation.Verbosity import matlab.unittest.plugins.DiagnosticsOutputPlugin suite = TestSuite.fromClass(?ExampleDiagOutputTest); runner = TestRunner.withNoPlugins();
创建一个默认 DiagnosticsOutputPlugin
,将其添加到运行器,然后运行测试。
plugin = DiagnosticsOutputPlugin; runner.addPlugin(plugin); result = runner.run(suite);
================================================================================ Verification failed in ExampleDiagOutputTest/testOne. ---------------- Test Diagnostic: ---------------- 42 == 13 --------------------- Framework Diagnostic: --------------------- verifyEqual failed. --> The numeric values are not equal using "isequaln". --> Failure table: Actual Expected Error RelativeError ______ ________ _____ ________________ 42 13 29 2.23076923076923 Actual Value: 42 Expected Value: 13 ------------------ Stack Information: ------------------ In C:\work\ExampleDiagOutputTest.m (ExampleDiagOutputTest.testOne) at 6 ================================================================================ Failure Summary: Name Failed Incomplete Reason(s) ============================================================================ ExampleDiagOutputTest/testOne X Failed by verification.
创建另一个测试运行器和一个 DiagnosticsOutputPlugin
,后者在 Terse
级别显示诊断信息(包括通过诊断信息),并显示在 Detailed
级别或更低级别记录的诊断信息。将其添加到运行器并重新运行测试。
runner = TestRunner.withNoPlugins(); plugin = DiagnosticsOutputPlugin('OutputDetail',Verbosity.Terse, ... 'LoggingLevel',3,'IncludingPassingDiagnostics',true); runner.addPlugin(plugin); result = runner.run(suite);
[Detailed] Diagnostic logged (2022-10-15 18:30:46): Testing failing event FAIL: ExampleDiagOutputTest/testOne in ExampleDiagOutputTest.testOne at 6 :: verifyEqual failed. [Detailed] Diagnostic logged (2022-10-15 18:30:47): Testing passing event PASS: ExampleDiagOutputTest/testTwo in ExampleDiagOutputTest.testTwo at 10 :: verifyTrue passed.
版本历史记录
在 R2018b 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)