Main Content

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) 创建一个插件,显示在任何级别记录的诊断,并显示通过事件诊断信息。

输入参量

全部展开

输出位置,指定为 OutputStream 类的实例。该插件将诊断信息定向到指定位置。默认情况下,插件使用 matlab.automation.streams.ToStandardOutput 流。

示例: matlab.automation.streams.ToFile('myFile.txt')

名称-值参数

将可选的参量对组指定为 Name1=Value1,...,NameN=ValueN,其中 Name 是参量名称,Value 是对应的值。名称-值参量必须出现在其他参量之后,但参量对组的顺序无关紧要。

在 R2021a 之前,使用逗号分隔每个名称和值,并用引号将 Name 引起来。

示例: DiagnosticsOutputPlugin('IncludingPassingDiagnostics',true,'OutputDetail',4) 创建一个插件,其中包括通过事件诊断信息并在“详尽”详细信息级别显示诊断信息。

是否排除来自失败事件的诊断信息,指定为 falsetrue。默认情况下,该插件包含来自失败事件的诊断信息。

数据类型: logical

是否包含通过事件的诊断信息,指定为 falsetrue。默认情况下,该插件不包含来自通过事件的诊断信息。

数据类型: logical

要在测试报告中包含的已记录诊断的最大详细级别,指定为从 04 的整数标量、matlab.automation.Verbosity 枚举对象或枚举的文本表示。插件包括在指定级别及更低级别记录的诊断。

数值表示枚举成员名称详细程度描述
0None

无信息

1Terse

最少的信息

2Concise

适中信息量

3Detailed

部分补充信息

4Verbose

大量补充信息

默认情况下,插件包含在 matlab.automation.Verbosity.Terse 级别(级别 1)记录的诊断信息。要排除所记录的诊断信息,请将 LoggingLevel 指定为 matlab.automation.Verbosity.None(级别 0)。

记录的诊断是您使用 log (TestCase)log (Fixture) 方法为测试框架提供的诊断。

示例: "LoggingLevel","detailed"

报告事件的详细信息级别,指定为介于 0 和 4 之间的整数值、matlab.automation.Verbosity 枚举对象,或对应于预定义枚举成员名称之一的字符串标量或字符向量。整数值对应于 matlab.automation.Verbosity 枚举的成员。

该插件使用 OutputDetail 指定的信息量来报告通过事件、失败事件和日志记录事件。默认情况下,该插件在 matlab.automation.Verbosity.Detailed 级别(级别 3)记录事件。

数值表示枚举成员名称详细程度描述
0None

无信息

1Terse

最少的信息

2Concise

适中信息量

3Detailed

部分补充信息

4Verbose

大量补充信息

属性

全部展开

此 属性 为只读。

表明是否排除失败事件的诊断信息的指示符,指定为 falsetruelogical 0 或 1)。默认情况下,ExcludeFailureDiagnosticsfalse,输出中包含来自失败事件的诊断信息。要从输出中排除失败事件的诊断信息,请在插件构造期间将 ExcludeFailureDiagnostics 指定为 true

此 属性 为只读。

表明是否包含通过事件的诊断信息的指示符,指定为 falsetruelogical 0 或 1)。默认情况下,IncludePassingDiagnosticsfalse,即不在输出中包含通过事件的诊断信息。要在输出中包含通过事件的诊断信息,请在构造插件时将 IncludePassingDiagnostics 指定为 true

此 属性 为只读。

插件包含的记录诊断信息的最高详细级别,以 matlab.automation.Verbosity 枚举对象形式返回。该插件包含在此级别和更低级别记录的诊断信息。默认情况下,此属性值为 matlab.automation.Verbosity.Terse。您可以在插件构造期间指定不同的日志记录级别。

记录的诊断信息是您通过调用 log (TestCase)log (Fixture) 方法提供给测试框架的诊断信息。

此 属性 为只读。

报告事件的详细信息级别,以 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 中推出