Main Content

sltest.testmanager.find

Find test case in test file

Since R2024a

Description

tcArray = sltest.testmanager.find finds all test cases in all open test files.

example

tfArray = sltest.testmanager.find(Name=Value) specifies options using one or more name-value arguments.

example

Examples

collapse all

This example shows how to find all the test cases in an open test file.

Open the test file, which has two test cases.

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

Find all the test cases in the file and display that two elements are returned in the array.

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

Display the two test objects from the test file.

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]

Clear the test file and close the Test Manager.

sltest.testmanager.clear
sltest.testmanager.close

This example shows how to find test cases that have specific text strings.

Load the Test File

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

Find Test Cases Matching Part of the Description

Use the regular expression name-value argument, RegExp, to search for speed in the test case Description. The returned array has two TestCase objects, which both have Test setting the speed as the description.

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.'

Find Test Cases by Using a Wildcard

This test file has six test cases:

tcs.png

Use the string, r* to find all test cases with names that contain the letter r followed by any other character.

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'

Clear the test file and close the Test Manager.

sltest.testmanager.clear
sltest.testmanager.close

Input Arguments

collapse all

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: sltest.testmanager.find(Parent="myTestFile.mldatx") finds all test cases in the myTestFile.mldatx file.

Parent of the test case, specified as a test file object, test suite object, test case path, or string or character vector that contains the name of the test file to which the test case belongs. If you use the Parent name-value argument, find searches only in open test files under the specified parent. If you specify a test file that is closed, it is loaded. If you do not use this name-value argument, find searches all open test files.

Name of the test case for which to search, specified as a string or character vector. To search for a pattern in the test case name, include the name-value argument RegExp=true.

Whether the test case to search for is enabled, specified as a numeric or logical 1 (true) or 0 (false). If you do not specify the Enable name-value argument, find returns both enabled and disabled test cases.

Name of the test file to which the test case belongs, specified as a string, character vector, or test file object.

Path of the test case, specified as a string or character vector. To search for a pattern in the test path name, include the name-value argument RegExp=true.

Example: TestPath="myTestFile > Test Suite 1 > Baseline Test Case"

Type of the case, specified as one of these values:

  • "baseline" — Baseline test

  • "equivalence" — Equivalence test

  • "simulation" — Simulation test

Test case description, specified as a string or character vector. To search for a pattern in the description, include the name-value argument RegExp=true.

Reason that the test case is disabled, specified as a string or character vector. To search for a pattern in the ReasonForDisabling property, include the name-value argument RegExp=true.

Test case tag, specified as a string or character vector. To search for a pattern in the Tag property, include the RegExp=true name-value argument.

Whether to find test cases by using regular expressions, specified as a numeric or logical 1 (true) or 0 (false). Use regular expressions to search for a pattern in these name-value arguments:

Example: Name="base",RegExp=true

Output Arguments

collapse all

Test cases that match the specified search filters, returned as an array of sltest.testmanager.TestCase objects.

Version History

Introduced in R2024a