Main Content

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

sltest.testmanager.TestResultContainer 类

命名空间: sltest.testmanager

来自 MATLAB 单元测试 runrunInParallel 的 MLDATX 测试文件结果的容器

自 R2022b 起

描述

sltest.testmanager.TestResultContainermatlab.unittest.TestResult 对象的 Details 属性中保存 sltest.testmanager.TestCaseResultsltest.testmanager.TestIterationResult。当您使用 matlab.unittest.TestRunner runrunInParallel 方法针对保存在 Simulink® Test™ MLDATX 测试文件中的测试用例运行测试时,会创建 TestResultContainer 对象。仅当您使用 sltest.plugins.TestManagerResultsPlugin 时才会创建 sltest.testmanager.TestResultContainer 对象。

sltest.testmanager.TestResultContainer 类是 handle 类。

创建对象

不要创建 sltest.testmanager.TestResultContainer 对象。当您使用 sltest.plugins.TestManagerResultsPlugin 并运行保存在 Simulink Test MLDATX 测试文件中的测试用例时,会自动创建 TestResultContainer 对象。

属性

全部展开

Simulink Test MLDATX 测试文件中的测试用例上使用 MATLAB 单元测试框架 runrunInParallel 的结果,在 TestResultContainer 中作为 sltest.testmanager.TestCaseResultsltest.testmanager.TestIterationResult 对象返回。

属性:

GetAccess
public
SetAccess
public
Dependent
true
NonCopyable
true

示例

全部折叠

此示例显示如何将测试管理器结果包含在使用 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: ''

版本历史记录

在 R2022b 中推出