Main Content

createTestForSubsystem

Class: sltest.testmanager.TestFile
Package: sltest.testmanager

(Not recommended) Create test harness and test case for subsystem in test file

sltest.testmanager.TestFile.createTestForSubsystem is not recommended. Use sltest.testmanager.createTestForComponent instead. For more information, see Compatibility Considerations.

Syntax

tc = createTestForSubsystem(tf,'Subsystem',subsystem)
tc = createTestForSubsystem(tf,'Subsystem',subsystem,Name,Value)

Description

tc = createTestForSubsystem(tf,'Subsystem',subsystem) creates a harness on the specified subsystem, Model block, Stateflow® chart, or another supported model component (see Test Harness and Model Relationship. It also creates a baseline test case and test suite in the specified Excel® file. This function also simulates the model and adds the input and the output files to the test case, as MAT-files. For more information, see Generate Tests and Test Harnesses for a Model or Components.

tc = createTestForSubsystem(tf,'Subsystem',subsystem,Name,Value) uses additional options specified by one or more Name,Value pair arguments. Use this syntax to use Microsoft® Excel files as input and output files.

Input Arguments

expand all

Test file, specified as an sltest.testmanager.TestFile object.

Full path of the subsystem, specified as a character vector or string array. If the subsystem or component is in a Model block, you do not have to include the name of the block in the path. You can specify only the top-level model and system or the component under test.

Example: 'f14/Controller'

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: 'CreateExcelFile',true,'Sheet','mysheet'

Model name at the top of the hierarchy if the subsystem is in a referenced model, specified as a character vector or string.

Example: 'TopModel','Plant'

Test case type to create, specified as 'baseline', 'equivalence', or 'simulation'.

Example: 'TestType','equivalence'

Option to simulate the model to obtain subsystem inputs to use as inputs in the created test harness, specified as a logical. If this property is true, the test harness uses the subsystem inputs from the model simulation. If this property is false, the test harness does not use the subsystem inputs from the simulation.

Example: 'UseSubsystemInputs',false

Pairs for Equivalence Testing

expand all

Simulation mode for simulation 1 of an equivalence test, specified as either "Normal" or "Accelerator". If you do not specify a simulation mode, the mode of the system under test is used.

Example: "Simulation1Mode","Normal"

Simulation mode for simulation 2 of an equivalence test, specified as one of these values:

  • "Normal"

  • "Accelerator"

  • "Rapid Accelerator"

  • "Software-in-the-Loop (SIL)"

  • "Processor-in-the-Loop (PIL)"

If you do not specify a simulation mode, the mode of the system under test is used. For information about simulation modes, see Choosing a Simulation Mode. If TestType is equivalence and Simulation2Mode is Software-in-the-Loop (SIL), an extra test harness is created in addition to the test case and test harness.

Example: "Simulation2Mode","Software-in-the-Loop (SIL)"

Pairs for MAT-Files

expand all

Input filename and path for MAT-files, specified as a character vector or string array. Include the file extension .mat.

Example: 'InputsLocation','C:\MATLAB\inputs_data.mat'

Filename and path to save baseline data to, specified as a character vector or string. Include the file extension .mat.

Example: 'BaselineLocation','C:\MATLAB\baseline_data.mat'

Pairs for Microsoft Excel Files

expand all

Option to use Excel format for inputs and, for baseline tests only, outputs, specified as true or false. If you use the ExcelFileLocation argument to specify the filename and location, you do not need to also use CreateExcelFile.

Example: 'CreateExcelFile',true

Filename and path to save the Excel file to, specified as a character vector or string. Include the extension .xlsx. If you specify a location, you do not need to also use the 'CreateExcelFile' option.

Note

If SLDVTestGeneration is true and HarnessSource is "Signal Editor", you cannot save data to an Excel file.

Example: 'ExcelFileLocation','C:\MATLAB\baseline_data.xlsx'

Name of the sheet to save Excel data to, specified as a character vector or string.

Example: 'Sheet','MySubsysTest'

Pairs for Simulink Design Verifier

expand all

Whether to generate tests using Simulink Design Verifier, specified as a logical. If this property is true, Simulink Design Verifier generates the tests to include in the test file. An error occurs if this property is true, but Simulink Design Verifier is not installed.

Note

To generate tests from Simulink Design Verifier, the system under test must be an atomic subsystem.

Example: 'SLDVTestGeneration',true

Input source block for the test harness, specified as "Inport" or "Signal Editor".

Example: "HarnessSource","Signal Editor"

Output Arguments

expand all

Test case, returned as an sltest.testmanager.testcase object.

Examples

expand all

Create a baseline test case and test harness for a subsystem in a model reference, then save the inputs in Excel format. Baseline tests are used primarily for debugging.

% Load the model
load_system('sltestBasicCruiseControl');

% Create a test file
tf = sltest.testmanager.TestFile('My Test File');

% Create test from subsystem
createTestForSubsystem(tf,'Subsystem',...
    'sltestBasicCruiseControl/Controller/PI Controller',...
    'TestType','baseline','CreateExcelFile',true);

Version History

Introduced in R2016a

expand all