Create test case and test harness for model or model component
creates a test case in the specified test file or test suite for the specified model
component. The test file must already exist unless tc
= createTestForComponent("TestFile",tf
,"Component",componentName
)CreateTestFile
is
set to true
.
creates a test case with additional options specified by one or more
tc
= createTestForComponent(___,Name,Value
)Name,Value
pair arguments. Specify name-value pair arguments after
the test file and component input arguments.
Create a baseline test case for the sltestCar
model and save the inputs in an Excel® file. A test harness is created automatically.
load_system('sltestCar'); tf = sltest.testmanager.TestFile('MyBaselineTestFile'); sltest.testmanager.createTestForComponent("TestFile",tf,... "Component","sltestCar",... "TestType","baseline",... "ExcelFileLocation",... "C:\MATLABdata\mybaseline_inputdata.xlsx");
Create an equivalence (back-to-back) test case for the Controller
component of the rtwdemo_sil_block
model.
load_system('rtwdemo_sil_block'); tf = sltest.testmanager.TestFile('MyB2BTestFile'); sltest.testmanager.createTestForComponent("TestFile",tf,... "Component","rtwdemo_sil_block/Controller",... "TestType","equivalence",... "SLDVTestGeneration",true,... "Simulation1Mode","Normal",... "Simulation2Mode","Software-in-the-Loop (SIL)");
tf
— Test file or suite to which to add the test casesltest.testmanager.TestFile
object | sltest.testmanager.TestSuite
object | string | character vectorTest file or test suite to which to add the test case, specified as an
sltest.testmanager.TestFile
or
sltest.testmanager.TestSuite
object, string or character vector.
If CreateTestFile
is false, the test file object must exist. If
CreateTestFile
is true
,
TestFile
is the path of a new test file, specified as a string or
character vector.
C
Example: "TestFile","myTestFile"
componentName
— Model or component to testSimulink.BlockPath
objectModel or component to test, specified as a string or character vector of the full
path or as a Simulink.BlockPath
object. You can specify
any model or block that is supported for test
harness generation. See Test Harness and Model Relationship for a list of components for which you can build test
harnesses.
Example: "Component","sf_car/shift_logic"
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
.
CreateTestFile,true
'CreateTestFile'
— Whether to create a new test filefalse
(default) | true
Whether to create a new test file, specified as specified as the comma-separated
pair consisting of "CreateTestFile" and true
or
false
.
Example: "CreateTestFile",true
'TopModel'
— Model name at top of hierarchyModel name at the top of the hierarchy if the component to test is in a referenced
model, specified as the comma-separated pair consisting of
"TopModel"
and as a string or character vector. If the
componentName
is a top model, do not use the
TopModel
property.
Example: "TopModel","Plant"
'TestType'
— Test case type"baseline"
(default) | "equivalence"
| "simulation"
Test case type, specified as the comma-separated pair consisting of
"TestType"
and "baseline"
,
"equivalence"
, or "simulation".
Example: "TestType","equivalence"
'CreateHarness'
— Whether to create a test harnesstrue
(default) | false
Whether to create a test harness for a model, specified as the comma-separated
pair consisting of "CreateHarness"
and true
or
false
. When the Component
is not a top-level
model or when test cases are generated using Simulink®
Design Verifier™, this option is set to true
automatically and a test
harness is always created. If the model being
tested is an export-function model, a Test Sequence scheduler block is created
automatically in the test harness.
Example: "CreateHarness",false
'UseComponentInputs'
— Option to simulate model to obtain inputstrue
(default) | false
Option to simulate the model to obtain component inputs for the created test
harness, specified as true
or false
. If this
property is true
, the test harness uses the inputs from the model
simulation. If this property is false
, the test harness does not
use the component inputs from the simulation.
Example: "UseComponentInputs",false
'FunctionInterface'
— Function interface for a reusable library subsystemFunction interface, specified as the comma-separated pair consisting of
"FunctionInterface"
and a string or character vector. Specify
FunctionInterface
to create tests for a reusable library
subsystem. The subsystem must be at the top level of the subsystem library and must
have a function interface.
Example: "FunctionInterface","single"
'Simulation1Mode'
— Simulation mode for simulation 1 of equivalence test"Normal"
| "Accelerator"
Simulation mode for simulation 1 of an equivalence test, specified as the
comma-separated pair consisting of "Simulation1Mode"
and either
"Normal"
or "Accelerator"
. If you do not
specify a simulation mode, the mode of the system under test is used. The required
test harness is created automatically for the simulation mode.
Example: "Simulation1Mode","Normal"
'Simulation2Mode'
— Simulation mode for simulation 2"Normal"
| "Accelerator"
| "Rapid Accelerator"
| "Software-in-the-Loop (SIL)"
| "Processor-in-the-Loop (PIL)"
Simulation mode for simulation 2 of an equivalence test, specified as the
comma-separated pair consisting of "Simulation2Mode"
and a valid
string or character vector. If you do not specify a simulation mode, the mode of the
system under test is used. 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)"
'InputsLocation'
— File path for storing logged inputs in MAT-fileFile path for storing logged inputs in a MAT-file, specified as the
comma-separated pair consisting of "InputsLocation"
and a character
vector or string array. Include the file extension .mat
. If you do
not specify an InputsLocation
, a default location is used.
Example: "InputsLocation","C:\MATLAB\inputs_data.mat"
'BaselineLocation'
— File path for storing baseline logged outputs in MAT-fileFile path for storing baseline logged output data in a MAT-file, specified as the
comma-separated pair consisting of "BaselineLocation"
and a
character vector or string. Include the file extension .mat
. If you
do not specify a BaselineLocation
, a default location is
used.
Example: "BaselineLocation","C:\MATLAB\baseline_data.mat"
'CreateExcelFile'
— Whether to use Excel format for inputs and outputsfalse
(default) | true
Whether to use Excel format for inputs and, for baseline tests only, outputs, specified as
the comma-separated pair consisting of "CreateExcelFile"
and either
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'
— File path for Excel fileFile path for the Excel file, specified as the comma-separated pair consisting of
"ExcelFileLocation"
and a character vector or string array.
Include the extension .xlsx
. If you specify a location, you do not
need to also use the "CreateExcelFile"
option. If you do not
specify an ExcelFileLocation
, the current working folder is used.
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"
'Sheet'
— Name of Excel sheet to save data toName of Excel sheet in which to save data, specified as the comma-separated pair
consisting of "Sheet"
and a character vector or string. If you do
not specify a Sheet
, the current working folder is used.
Example: "Sheet","MySubsysTest"
'SLDVTestGeneration'
— Whether to generate tests using Simulink Design Verifierfalse
(default) | true
Whether to generate tests using Simulink
Design Verifier, specified as the comma-separated pair consisting of
"SLDVTestGeneration"
and true
or
false
.
Note
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 the comma-separated pair
consisting of "HarnessSource"
and either
"Inport"
or "Signal Editor"
.
Example: "HarnessSource","Signal Editor"
'HarnessOptions'
— Test harness creation optionsTest harness creation options, specified as a cell array of comma-separated
name-value pairs. See sltest.harness.create
for valid
options. Do not include the harnessOwner
handle as the first
argument in the cell array. The first argument is set automatically to the
Component
value.
Example: {"HarnessOptions","SynchronizationMode","SyncOnOpen","SeparateAssessment",true}
tc
— Test casesltest.testmanager.TestCase
objectTest case, returned as an sltest.testmanager.TestCase
object.