Main Content

sltest.testmanager.TestIteration class

Package: sltest.testmanager

Create or modify test iteration

Description

Iterations let you test a combination of model settings for testing methods such as Monte Carlo and parameter sweeping. Iterations initialize during test execution but before model callbacks and test callbacks. Once you create a test iteration object, you can override aspects of the test case for each iteration using the class methods.

You create your iteration script in the text window under the Iterations section of a test case. Iteration scripts cannot run in the MATLAB® command window.

Scripted iterations section of the Test Manager

The examples scripts in this reference page must be inserted into this section and other sections of the test case must be defined. For more information on iterations and scripted iterations, see Test Iterations.

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

Class Attributes

HandleCompatible
true

For information on class attributes, see Class Attributes.

Creation

iterationObj = sltest.testmanager.TestIteration returns a test iteration object. The object is used to construct a single iteration in a test case. Each iteration you want to create in the test must use a single iteration object.

You can also create a test iteration within a iteration script using the sltestiteration function.

If you use a for loop in the MATLAB command window to add many iterations to a test case, then the MATLAB command window might become temporarily unusable. Instead, use vectorization in the command window to add iterations to a test case. For example:

iterations(100) = sltest.testmanager.TestIteration; 
addIteration(tc,iterations);

Properties

expand all

Name of the test iteration, specified as a character vector. The iteration name must be unique from other iterations in the test case.

Example: 'Iteration 1a'

Attributes:

SetAccess
public
GetAccess
public
Dependent
true
NonCopyable
true

Set of model parameter overrides for the iteration, returned as a cell array of character vectors.

Attributes:

SetAccess
protected
GetAccess
public
Dependent
true
NonCopyable
true

Set of test parameter settings for the iteration, returned as a cell array of character vectors.

Attributes:

SetAccess
protected
GetAccess
public
Dependent
true
NonCopyable
true

Set of model variable overrides for the iteration, returned as a cell array of character vectors.

Attributes:

SetAccess
protected
GetAccess
public
Dependent
true
NonCopyable
true

Option to run the iteration with the test case, specified as a logical.

Attributes:

SetAccess
public
GetAccess
public
Dependent
true
NonCopyable
true

Methods

expand all

Examples

collapse all

In this example of a scripted iteration, specify the model in the test case to be sldemo_absbrake. The iterations are generated during test execution. This section of script is in the Scripted Iterations section of the test case. It will execute only in the Scripted Iterations section. The sltest_testCase is a variable defined for you in the Scripted Iterations section, which is the parent test case object of the iteration.

% Open the model for this example
openExample('sldemo_absbrake');

% Specify the parameter sweep
vars = 32 : 0.5 : 34;

% Create iteration for each parameter using a loop
for k = 1 : length(vars)

    % Create test iteration object
    testItr = sltest.testmanager.TestIteration;

    % Set the parameter value for this iteration
    setVariable(testItr,'Name','g','Source',...
       'base workspace','Value',vars(k));

    str = sprintf('Iteration %d',k);

    % Add the iteration object to the test case
    addIteration(sltest_testCase,testItr,str);
end

In this example of a scripted iteration, there must be parameter sets defined in the Parameter Overrides section of the test case. The iterations are generated during test execution. This section of script is in the Scripted Iterations section of the test case. It will execute only in the Scripted Iterations section. The sltest_testCase is a variable defined for you in the Scripted Iterations section, which is the parent test case object of the iteration.

% Define parameter sets for a test case and add this code in the

% Scripted iterations section of the test case
for k = 1 : length(sltest_parameterSets)

    % Create test iteration object    
    testItr = sltest.testmanager.TestIteration;

    % Use the parameter set in this iteration
    testItr.setTestParam('ParameterSet',sltest_parameterSets{k});
    
    str = sprintf('ParameterSet %d',k);

    % Add the iteration object to the test case
    addIteration(sltest_testCase,testItr,str);
end

Alternatives

If you do not want to use a script to create iterations, then you can use table iterations in the test case. For more information about table iterations, see Test Iterations.

Introduced in R2016a