sltest.testmanager.createTestForComponent

Create test case and test harness for model or model component

Description

example

tc = createTestForComponent("TestFile",tf,"Component",componentName) creates a test case in the specified test file or test suite for the specified model component. The test file must already exist unless CreateTestFile is set to true.

example

tc = createTestForComponent(___,Name,Value) creates a test case with additional options specified by one or more Name,Value pair arguments. Specify name-value pair arguments after the test file and component input arguments.

Examples

collapse all

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)");

Input Arguments

collapse all

Test 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"

Model 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"

Name-Value Pair Arguments

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.

Example: CreateTestFile,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

Model 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"

Test case type, specified as the comma-separated pair consisting of "TestType" and "baseline", "equivalence", or "simulation".

Example: "TestType","equivalence"

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

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

Function 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"

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"

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)"

File 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"

File 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"

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

File 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"

Name 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"

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

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"

Test 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}

Output Arguments

collapse all

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

Introduced in R2020b