Main Content

本页采用了机器翻译。点击此处可查看英文原文。

sltest.plugins.TestManagerResultsPlugin 类

命名空间: sltest.plugins

使用 MATLAB 单元测试框架生成增强的测试结果

描述

当使用 MATLAB® 单元测试框架运行 Simulink® Test™ 文件时,使用 sltest.plugins.TestManagerResultsPlugin 类来包含测试管理器结果。测试用例和测试迭代结果出现在 TestResultContainer 类中。

要发布测试管理器结果,请配置测试文件以进行报告,并将 TestReportPluginTestManagerResultsPlugin 类添加到 TestRunner 对象。测试用例和测试迭代结果出现在 MATLAB 测试报告的详细信息部分。有关更多信息,请参阅 测试持续集成系统模型

创建对象

tmr = sltest.plugins.TestManagerResultsPlugin 创建 sltest.plugins.TestManagerResultsPlugin 插件对象 tmr。您仅使用插件对象来指示 TestRunner 产生增强的测试结果。

您也可以导入插件,然后使用类名创建对象:

import sltest.plugins.TestManagerResultsPlugin
tmr = TestManagerResultsPlugin

输入参量

全部展开

名称-值参数

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

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

示例: 'ExportToFile','myfile'

可选文件,用于以 Simulink Test MLDATX 格式保存结果,指定为由 'ExportToFile' 和文件名组成的逗号分隔对。

您可以通过单击工具栏上的导入按钮在测试管理器中打开 MLDATX 结果文件。

注意

确保 sltest.plugins.TestManagerResultsPlugin 仅添加到 TestRunner 对象一次。多次添加插件可能会导致导出测试结果文件出现问题。

示例: 'ExportToFile','myfile'

示例: 'ExportToFile','myfile.mldatx'

示例

全部折叠

此示例显示如何将测试管理器结果包含在使用 MATLAB 单元测试框架生成的 TestResult 对象中。结果存储在 TestResultContainer 对象中。

测试用例向控制器子系统创建一个方波输入,并扫描参数 ab 的 25 次迭代。该测试将 alpha 输出与容差为 0.0046 的基线进行比较。超出此容差的输出将导致测试失败。

1.设置测试文件的路径。

testfile = 'f14ParameterSweepTest.mldatx';

2.创建 TestSuite 对象。

import matlab.unittest.TestSuite
suite = testsuite(testfile);

3.创建 TestRunner 对象。

import matlab.unittest.TestRunner
runner = TestRunner.withNoPlugins;

4.将 TestManagerResultsPlugin 添加到 TestRunner.

tmr = sltest.plugins.TestManagerResultsPlugin; 
addPlugin(runner,tmr)

5.运行测试。

results = run(runner,suite);

6.查看第 19 次迭代的结果,测试失败。

failure = results(19)
failure = 
  TestResult with properties:

          Name: 'f14ParameterSweepTest > New Test Suite 1/Iterations Parameter Sweep(ScriptedIteration=Scripted_Iteration19)'
        Passed: 0
        Failed: 1
    Incomplete: 0
      Duration: 1.0174
       Details: [1x1 struct]

Totals:
   0 Passed, 1 Failed, 0 Incomplete.
   1.0174 seconds testing time.

TestResult 对象的 Details 字段中,测试迭代结果存储在 TestResultContainer 对象中,您无法直接与该对象交互。TestResultContainer 对象包含测试用例或测试迭代对象,您可以使用它来检索测试结果信息,例如测试用例的类型、失败的原因以及导致失败的参数值。

failresult = failure.Details.SimulinkTestManagerResults.TestResult;
failresult.TestCaseType
ans = 
'Baseline Test'
failresult.CauseOfFailure
ans = 
'Failed criteria: Baseline'
failresult.IterationSettings.variableParameters(1)
ans = struct with fields:
      parameterName: 'a'
             source: 'base workspace'
              value: 2.6000
       displayValue: '2.6'
    simulationIndex: 1
     rrPropertyType: ''
     rrPropertyName: ''

failresult.IterationSettings.variableParameters(2)
ans = struct with fields:
      parameterName: 'b'
             source: 'base workspace'
              value: 66
       displayValue: '66'
    simulationIndex: 1
     rrPropertyType: ''
     rrPropertyName: ''

版本历史记录

在 R2018b 中推出