Main Content

sltest.harness.SimulationInput Class

Namespace: sltest.harness

Create test harness simulation input for MATLAB-based Simulink tests

Since R2020b

Description

Use objects of the sltest.harness.SimulationInput to specify the changes applied to a test harness during simulation. After simulation, the harness is restored to its state before simulation. This object is used with MATLAB®-based Simulink® tests. sltest.harness.SimulationInput is a subclass of Simulink.SimulationInput.

The sltest.harness.SimulationInput class is a handle class.

Class Attributes

Sealed
true
RestrictsSubclassing
true

For information on class attributes, see Class Attributes.

Creation

Description

example

in = sltest.harness.SimulationInput(owner,name) creates and returns a SimulationInput object and sets the HarnessOwner property to owner and the HarnessName property to name.

Alternatively, use the createSimulationInput method of sltest.TestCase to create a sltest.harness.SimulationInput object.

Properties

expand all

Model or component that owns the harness, specified as a string, character vector, or a model or component handle.

Name of the test harness for which to a create simulation input object, specified as a string or character vector.

In addition to HarnessName and HarnessOwner properties, sltest.harness.SimulationInput has the properties of Simulink.SimulationInput.

Methods

expand all

Examples

collapse all

This myBaselineTest.m class definition file defines a test case that compares a set of baseline values and values produced from a simulation. This example uses a SimulationInput object to set harness variable values. See Using MATLAB-Based Simulink Tests in the Test Manager for the full example that includes the baseline data file and other files and commands required to run this test.

The first line of the file shows the inheritance from sltest.TestCase. The method function section, which has a Test attribute, contains the testOne test case. The test case loads a model, creates a input object, sets some variable values, simulates the harness, and verifies whether the simulation and baseline signals match.

classdef myBaselineTest < sltest.TestCase
   methods (Test)
      function testOne(testCase)
         testCase.loadSystem('sltest_ratelim');
         in = sltest.harness.SimulationInput('sltest_ratelim',...
            'sltest_ratelim_Harness1');           
         in = in.setVariable('t_gain',[0;2],
            'Workspace','sltest_ratelim');
         in = in.setVariable('u_gain',[-0.02;-4.02],
            'Workspace','sltest_ratelim');
         simOut = testCase.simulate(in);
         testCase.verifySignalsMatch(simOut,'baseline1.mat');
      end
   end
end

Then, at the command line, create a test suite, a test runner to run the test, add coverage, and push the test results to the Test Manager. Open the Test Manager to view the results.

suite = testsuite('myBaselineTest');
runner = testrunner("textoutput");
runner.addModelCoverage;
runner.addSimulinkTestResults;
runner.run(suite);

Version History

Introduced in R2020b