Main Content

loadSystem

Class: sltest.TestCase
Namespace: sltest

Load model for MATLAB-based Simulink test

Since R2020b

Description

[modelname,modelhandle,modelpath] = loadSystem(testCase,model) loads the specified model and returns the name of the model, the model handle, and the path to the model.

loadSystem loads a Simulink model within the scope of a single TestCase method class. The life cycle of the model is tied to the test case. When the test case goes out of scope, the testing framework closes the model without saving any changes to the model and clears any base workspace variables loaded by the model. Previously loaded models remain loaded. Variable values of previously loaded models might be overridden if, for example, the model being opened has model callbacks. To retain the variable values of opened models, add PreservingBaseWorkspace as an input Name-Value pair.

example

[modelname,modelhandle,modelpath] = loadSystem(___,Name,Value) loads the model and test case with additional options specified by one or more Name,Value pairs.

example

Input Arguments

expand all

Instance of the test case, specified as an sltest.TestCase object.

Name of model to load, specified as a string or character vector.

Example: "sf_car"

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: 'PreservingBaseWorkspace',true

Whether to preserve existing base workspace variable values, specified as the comma-separated pair consisting of 'PreservingBaseWorkspace' and true or false.

Whether to load the model and its referenced models, specified as the comma-separated pair consisting of 'IncludingReferencedModels' and true or false.

Output Arguments

expand all

Name of the loaded model, returned as a string or character vector. If 'IncludingReferencedModels' is true, then loadSystem returns the model name and the names of its referenced models.

Handle of the loaded model, returned as a string or character vector. If IncludeReferencedModels is true, returns the handle of the model and the handles of its referenced models.

Path of the loaded model, returned as a string or character vector. If IncludeReferencedModels is true, returns the path of the model and the paths of its referenced models.

Attributes

Accesspublic

To learn about attributes of methods, see Method Attributes.

Examples

expand all

classdef simTest < sltest.TestCase
   methods (Test)
      function testOne(testCase)
         [modelname,modelhandle,modelpath] =...
            testCase.loadSystem('myModel');
      end
   end
end
 classdef simTest < sltest.TestCase
    methods (Test)
        function testOne(testCase)
           [modelname,modelhandle,modelpath] =...
              testCase.loadSystem('myModel',...
              'IncludingReferencedModels',true);
        end
    end
end

Version History

Introduced in R2020b