Main Content

sltest.TestCase class

Package: sltest

Test case class for MATLAB-based Simulink tests integrated with Test Manager


The sltest.TestCase class enables authoring MATLAB®-based Simulink® tests. You define a MATLAB-based Simulink test in a .m file that inherits from sltest.TestCase. Since sltest.TestCase is a matlab.unittest.TestCase, the matlab.unittest.TestCase methods and behaviors are available when authoring a MATLAB-based Simulink test.

The sltest.TestCase class is a handle class.

Class Attributes


For information on class attributes, see Class Attributes.


To create a test that you can load, run, and analyze its results in the Test Manager, create a class definition file that inherits from sltest.TestCase. The file contains methods that define the test case.

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


expand all


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)

         in = testCase.createSimulationInput('sltest_ratelim',...
         in = in.setVariable('t_gain',[0;2],...
         in = in.setVariable('u_gain',[-0.02;-4.02],...

         simOut = testCase.simulate(in);

Version History

Introduced in R2020b