Main Content

sltest.testmanager.TestOptions class

Package: sltest.testmanager

Options for adding test coverage

Description

Use an sltest.testmanager.TestOptions object to specify the options to use when you add missing coverage to a test. Use this object with sltest.testmanager.addTestsForMissingCoverage.

The sltest.testmanager.TestOptions class is a handle class.

Creation

testOpts = sltest.testmanager.TestOptions() creates a TestOptions object with default properties. After creating the object, set the TestFilePath, TestCase, Parent, HarnessOwner, and HarnessName properties.

testOpts = sltest.testmanager.TestOptions(tc) creates a TestOptions object for the sltest.testmanager.TestCase object, tc. Use this syntax to append added coverage to the test case. The TestFilePath, Parent, HarnessOwner, and HarnessName properties are automatically populated.

testOpts = sltest.testmanager.TestOptions(harnessOwner,harnessName) creates a TestOptions object for the test harness, harnessName, that is associated with model or model element, harnessOwner. Use this syntax to reuse a test harness for a new test case.

Properties

expand all

Model name, specified as a string.

Attributes:

GetAccess
public
SetAccess
public

Test file name, specified as a string. If you specify values for either or both the TestCase and Parent properties, the TestFilePath must be the same as the FilePath of the existing test case or parent. If you do not specify values for both TestCase and Parent, you must specify a TestFilePath for a new or existing test file.

Example: "TestFilePath","myTests/baseline_test2.mldatx"

Attributes:

GetAccess
public
SetAccess
public

Name of new or existing test case for which to add coverage, specified as an sltest.testmanager.TestCase object.

Attributes:

GetAccess
public
SetAccess
public

Test suite that contains the test case, specified as a sltest.testmanager.TestSuite object.

Attributes:

GetAccess
public
SetAccess
public

Type of test, specified for new test cases or iterations as "baseline", "equivalence", or "simulation". For existing test cases, this property is automatically set to the type of the specified test case.

Attributes:

GetAccess
public
SetAccess
public

Simulation index for equivalence tests, specified as 1, 2, or [1,2]. Specifying 1 or 2 adds the missing coverage for the first or second simulation, respectively. Specifying [1,2] adds coverage for both simulations.

Attributes:

GetAccess
public
SetAccess
public

Harness owner, specified as a string. HarnessOwner is the model or model element with which the harness is associated. Specify a harness owner only if you are creating a new harness. For existing harnesses, this property is automatically set to the owner of the specified harness.

Attributes:

GetAccess
public
SetAccess
public

Harness name, specified as a string. Specify a harness name only if you are creating a new harness. For existing harnesses, this property is automatically set to the name of the specified harness.

Attributes:

GetAccess
public
SetAccess
public

Harness input source, specified as "Inport" or "Signal Editor".) Specify the source only if you are creating a new harness. For existing harnesses, this property is automatically set to the source of the specified harness.

Attributes:

GetAccess
public
SetAccess
public

Examples

collapse all

Create a TestOptions object to add coverage by using a new test case.

testOpts = sltest.testmanager.TestOptions()
testOpts = 

  TestOptions with properties:

            Model: ""
     TestFilePath: ""
         TestCase: [0×0 sltest.testmanager.TestCase]
           Parent: [0×0 sltest.testmanager.TestSuite]
     TestCaseType: Baseline
      SrcSimIndex: 1
     HarnessOwner: ""
      HarnessName: ""
    HarnessSource: INPORT

This example shows how increase coverage when coverage results for a test case are lower than 100%.

Get the existing test case from the test file and then run the test and get the coverage data. Create a TestOptions object and add missing coverage to the coverage data for new test case. Run the new test case and open the Test Manager.

load_system("CruiseControlAddCov.slx");

tf = sltest.testmanager.TestFile('CruiseControlAddCov.mldatx');
ts = getTestSuites(tf); 
testcaseObj = getTestCases(ts); 

tr = run(testcaseObj);
cvdata = getCoverageResults(tr);

testOpts = sltest.testmanager.TestOptions(testcaseObj); 
newTestCaseObj = sltest.testmanager.addTestsForMissingCoverage...
   (testOpts,cvdata);

tr = run(newTestCaseObj);

sltest.testmanager.view;

In the Results and Artifacts panel in the Test Manager, select the first Results. In the Aggregated Coverage Results section, the coverage is less than 100%.

Now, select the second Results. In the Aggregated Coverage Results section, the coverage increased to 100%.

Clear and close the Test Manager.

sltest.testmanager.clear
sltest.testmanager.clearResults
sltest.testmanager.close

Version History

Introduced in R2022a