Main Content

sltest.TestCase Class

Namespace: sltest

Test case class for MATLAB-based Simulink tests

Since R2020b

Description

The sltest.TestCase class enables authoring MATLAB®-based Simulink® tests. You define a MATLAB-based Simulink test in a MATLAB code .m file that inherits from sltest.TestCase. The types of MATLAB-based Simulink tests include MATLAB unit testing framework tests and ASAM® XIL framework tests. For the unit testing framework tests, you can use matlab.unittest.TestCase methods. For ASAM XIL, you must install the Simulink Test™ Support Package for ASAM XIL Standard and use the methods of sltest.xil.framework.Framework and its associated FrameworkConfiguration, TestVariable, Stimulation, and Acquisition classes.

The sltest.TestCase class is a handle class.

Class Attributes

Abstract
true

For information on class attributes, see Class Attributes.

Creation

To create a MATLAB unit testing framework test that you can load, run, and analyze its results in the Test Manager, or an ASAM XIL framework test to run tests on a test bench, create a class definition file that inherits from sltest.TestCase. The file contains methods that define the test case.

For debugging a MATLAB unit testing framework test at the command line without having to run an sltest.TestCase test, use the forInteractiveUse static method to create a TestCase.

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 using the simulate method. 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 and then load it into the Test Manager.

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

classdef myBaselineTest < sltest.TestCase
   methods (Test)
      function testOne(testCase)
         testCase.loadSystem('sltest_ratelim');

         in = testCase.createSimulationInput('sltest_ratelim',...
            'WithHarness','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

Note

For an example using the ASAM XIL framework, see Create Tests Using the Simulink Test Support Package for ASAM XIL Standard.

Version History

Introduced in R2020b