Main Content

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

sltest.testmanager.find

在测试文件中查找测试用例

自 R2024a 起

说明

tcArray = sltest.testmanager.find 在所有打开的测试文件中找到所有测试用例。

示例

tfArray = sltest.testmanager.find(Name=Value) 使用一个或多个名称值参量指定选项。

示例

示例

全部折叠

此示例显示如何在打开的测试文件中找到所有测试用例。

打开测试文件,里面有两个测试用例。

sltest.testmanager.load("RollRefTest.mldatx");

查找文件中的所有测试用例,并显示数组中返回两个元素。

tcArray = sltest.testmanager.find
tcArray=1×2 TestCase array with properties:
    Name
    TestFile
    TestPath
    TestType
    RunOnTarget
    RunOnPlatform
    Parent
    Requirements
    Description
    Enabled
    ReasonForDisabling
    Tags

numel(tcArray)
ans = 2

显示测试文件中的两个测试对象。

tcArray(1),tcArray(2)
ans = 
  TestCase with properties:

             Name: 'Requirement 1.3 Test'
         TestFile: [1x1 sltest.testmanager.TestFile]
         TestPath: 'RollRefTest > Basic Design Test Cases > Requirement 1.3 Test'
         TestType: 'simulation'
      RunOnTarget: {[0]}
    RunOnPlatform: {[Desktop]}
           Parent: [1x1 sltest.testmanager.TestSuite]
     Requirements: [0x1 struct]
      Description: ''
          Enabled: [1]
             Tags: [0x0 string]

ans = 
  TestCase with properties:

             Name: 'RollReference Timeseries Input'
         TestFile: [1x1 sltest.testmanager.TestFile]
         TestPath: 'RollRefTest > Logged Data and Coverage > RollReference Timeseries Input'
         TestType: 'simulation'
      RunOnTarget: {[0]}
    RunOnPlatform: {[Desktop]}
           Parent: [1x1 sltest.testmanager.TestSuite]
     Requirements: [0x1 struct]
      Description: ''
          Enabled: [1]
             Tags: [0x0 string]

清除测试文件并关闭测试管理器。

sltest.testmanager.clear
sltest.testmanager.close

此示例显示如何查找具有特定文本字符串的测试用例。

加载测试文件

sltest.testmanager.load('cruiseControlRBTCovTests.mldatx');

查找符合部分描述的测试用例

使用正则表达式名称值参量 RegExp 在测试用例 Description 中搜索 speed。返回的数组有两个 TestCase 对象,它们都以 Test setting the speed 作为描述。

tcArray1 = sltest.testmanager.find(Description='speed',RegExp=true)
tcArray1=1×2 TestCase array with properties:
    Name
    TestFile
    TestPath
    TestType
    RunOnTarget
    RunOnPlatform
    Parent
    Requirements
    Description
    Enabled
    ReasonForDisabling
    Tags

tcArray1(1).Name,tcArray1(1).Description
ans = 
'Set Speed Test'
ans = 
'Test setting the speed.'
tcArray1(2).Name,tcArray1(2).Description
ans = 
'Throttle Test'
ans = 
'Test setting the speed.'

使用通配符查找测试用例

该测试文件有六个测试用例:

tcs.png

使用字符串 r* 查找名称包含字母 r 且后跟任何其他字符的所有测试用例。

tcArray2 = sltest.testmanager.find(Name='r*',RegExp=true)
tcArray2=1×4 TestCase array with properties:
    Name
    TestFile
    TestPath
    TestType
    RunOnTarget
    RunOnPlatform
    Parent
    Requirements
    Description
    Enabled
    ReasonForDisabling
    Tags

tcArray2.Name
ans = 
'Brake Test'
ans = 
'Increment Test'
ans = 
'Decrement Test'
ans = 
'Throttle Test'

清除测试文件并关闭测试管理器。

sltest.testmanager.clear
sltest.testmanager.close

输入参数

全部折叠

名称-值参数

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

示例: sltest.testmanager.find(Parent="myTestFile.mldatx") 查找 myTestFile.mldatx 文件中的所有测试用例。

测试用例的父级,指定为测试文件对象、测试套件对象、测试用例路径,或者包含测试用例所属的测试文件的名称的字符串或字符向量。如果使用 Parent 名称值参量,则 find 仅在指定父级下的打开的测试文件中搜索。如果您指定一个已关闭的测试文件,则会加载该文件。如果不使用此名称值参量,find 将搜索所有打开的测试文件。

要搜索的测试用例的名称,指定为字符串或字符向量。要在测试用例名称中搜索模式,请包含名称值参量 RegExp=true

要搜索的测试用例是否启用,指定为数字或逻辑 1 (true) 或 0 (false)。如果不指定 Enable 名称值参量,find 将返回启用和禁用的测试用例。

测试用例所属的测试文件的名称,指定为字符串、字符向量或测试文件对象。

测试用例的路径,指定为字符串或字符向量。要在测试路径名称中搜索模式,请包含名称值参量 RegExp=true

示例: TestPath="myTestFile > Test Suite 1 > Baseline Test Case"

用例类型,指定为以下值之一:

  • baseline” — 基线测试

  • equivalence” — 等价检验

  • simulation” — 仿真测试

测试用例描述,指定为字符串或字符向量。要在描述中搜索模式,请包含名称值参量 RegExp=true

测试用例被禁用的原因,指定为字符串或字符向量。要在 ReasonForDisabling 属性中搜索模式,请包含名称值参量 RegExp=true

测试用例标签,指定为字符串或字符向量。要在 Tag 属性中搜索模式,请包含 RegExp=true 名称值参量。

是否使用正则表达式查找测试用例,指定为数字或逻辑 1 (true) 或 0 (false)。使用正则表达式在这些名称-值参量中搜索模式:

示例: Name="base",RegExp=true

输出参量

全部折叠

与指定搜索过滤器匹配的测试用例,以 sltest.testmanager.TestCase 对象数组的形式返回。

版本历史记录

在 R2024a 中推出