Class: sltest.testmanager.TestFile
Package: sltest.testmanager
Create test harness and test case for subsystem in test file
harn_tc = createTestForSubsystem(tf,'Subsystem',subsystem)
l = createTestForSubsystem(tf,'Subsystem',subsystem,Name,Value)
creates a harness on the specified subsystem, model reference 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 test 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 for a Component.harn_tc
= createTestForSubsystem(tf
,'Subsystem',subsystem
)
uses additional options specified by one or more l
= createTestForSubsystem(tf
,'Subsystem',subsystem
,Name,Value
)Name,Value
pair
arguments. Use this syntax to use Microsoft®
Excel® files as input and output files.
tf
— Test filesltest.testmanager.TestFile
objectTest file, specified as an sltest.testmanager.TestFile
object.
subsystem
— Subsystem pathFull 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'
Specify optional
comma-separated pairs of Name,Value
arguments. Name
is
the argument name and Value
is the corresponding value.
Name
must appear inside quotes. You can specify several name and value
pair arguments in any order as
Name1,Value1,...,NameN,ValueN
.
'CreateExcelFile',true,'Sheet','mysheet'
'TopModel'
— Model name at top of hierarchyModel 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'
'TestType'
— Test case type'baseline'
(default) | 'equivalence'
| 'simulation'
Test case type to create, specified as 'baseline'
,
'equivalence'
, or
'simulation'
.
Example: 'TestType','equivalence'
'UseSubsytemInputs'
— Option to simulate model to obtain inputstrue
(default) | false
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: 'UseSubstyemInputs',false
'Simulation1Mode'
— Simulation mode for simulation 1"Normal"
| "Accelerator"
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"
'Simulation2Mode'
— Simulation mode for simulation 2Simulation 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 (Simulink).
Example: "Simulation2Mode","Software-in-the-Loop
(SIL)"
'InputsLocation'
— Input file name and path for MAT-filesInput file name 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'
'BaselineLocation'
— Baseline file locationFile name 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'
'CreateExcelFile'
— Use Excel format for inputs and outputsfalse
(default) | true
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 file
name and location, you do not need to also use
CreateExcelFile
.
Example: 'CreateExcelFile',true
'ExcelFileLocation'
— Name and location for Excel fileFile name 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.
If SLDVTestGeneration
is
true
and
HarnessSource
is "Signal
Editor"
, you cannot save data to an Excel
file.
Example: 'ExcelFileLocation','C:\MATLAB\baseline_data.xlsx'
'Sheet'
— Name of Excel sheet to save data toName of the sheet to save Excel data to, specified as a character vector or string.
Example: 'Sheet','MySubsysTest'
'SLDVTestGeneration'
— Whether to generate tests using Simulink® Design Verifier™false
(default) | true
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.
To generate tests from Simulink Design Verifier, the system under test must be an atomic subsystem.
Example: 'SLDVTestGeneration',true
'HarnessSource'
— Input source block for the harness"Inport"
(default) | "Signal Editor"
Input source block for the test harness, specified as
"Inport"
or "Signal Editor"
.
Example: "HarnessSource","Signal
Editor"
harn_tc
— Harness and test case creation resultReturns 0 if the harness and test case are not created, or 1 if the harness and test case are created.
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);
Create an equivalence test case and test harness for a subsystem, then save the inputs in Excel format.
% Load the model load_system('rtwdemo_sil_block'); % Create a test file tf = sltest.testmanager.TestFile('My B2B Test File'); % Create test from subsystem createTestForSubsystem(tf,'Subsystem',... 'rtwdemo_sil_block/Controller','TestType',... 'equivalence','Simulation1Mode','Normal',... 'Simulation2Mode','Software-in-the-Loop (SIL)',... 'CreateExcelFile',true);