主要内容

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

sltest.testmanager.TestResultContainer 类

R2025b

命名空间: sltest.testmanager

来自 MATLAB 单元测试 run 或 runInParallel 的 MLDATX 测试文件结果的容器

自 R2022b 起

描述

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

sltest.testmanager.TestResultContainer 类是一个 handle 类。

创建对象

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

属性

全部展开

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

属性:

GetAccess
public
SetAccess
public
Dependent
true
NonCopyable
true

示例

全部折叠

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

测试用例向控制器子系统创建一个方波输入,并扫描参数 a 和 b 的 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: 0.4843
       Details: [1×1 struct]

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

在 Details 对象的 TestResult 字段中,测试迭代结果存储在 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 中推出