Class: sltest.testmanager.TestCase
Package: sltest.testmanager
Add input file to test case
adds a file to the Inputs section of the test case and returns a
test input object, input
= addInput(tc
,file
,Name,Value
)sltest.testmanager.TestInput
.
tc
— Test casesltest.testmanager.TestCase
objectTest case that you want to add the test input to, specified
as a sltest.testmanager.TestCase
object.
file
— Input file name and pathName and path of MAT-file or Microsoft® Excel® input file, specified as a character vector.
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
.
'Sheets','mysheet','Ranges','C1:F10','CreateIterations',false
'SimulationIndex'
— Test case simulation numberTest case simulation number that the inputs
apply to, specified as 1
or
2
. This setting applies to
equivalence tests.
Example: 'SimulationIndex',2
'CreateIterations'
— Create a table iteration from the inputOption to add the input file to the iteration table under Iterations in the test case, specified as Boolean.
Example: 'CreateIterations',false
'Sheets'
— Names of sheets to use as inputsNames of sheets from Excel file to use as test case inputs, specified as a character vector, string, or array of strings.
Example: 'testinputs'
,
["Heater","Plant"]
'Ranges'
— Range of cells from sheetRanges of cells from the sheets that you
added as inputs, specified as a character vector, string, or array of strings.
You can specify 'Ranges'
only if you also specify
'Sheets'
. The ranges you specify must correspond to the
sheets. For example, if you specify one sheet, specify one range. If you
specify a cell array of sheets, each value in the 'Ranges'
cell array must correspond with a sheet in the 'Sheets'
cell
array.
You can specify 'Ranges'
as shown in the table.
Ways to specify Range
| Description |
---|---|
Rectangular Range |
Specify the range using the syntax
Example:
|
Unspecified or Empty | If unspecified, the importing function automatically detects the used range. Example:
Note: Used Range refers to the rectangular portion of the spreadsheet that actually contains data. The importing function automatically detects the used range by trimming leading and trailing rows and columns that do not contain data. Text that is only white space is considered data and is captured within the used range. |
Row Range |
You can identify the range by specifying the beginning and
ending rows using Excel row designators. Then Example:
|
Column Range | You can identify the range by specifying the beginning
and ending columns using Excel column designators. Then
Example:
|
Excel’s Named Range |
In Excel, you can create names to identify ranges in the
spreadsheet. For instance, you can select a rectangular portion
of the spreadsheet and call it Example:
|
Example: 'B2:C30'
,
"D2:E30"
, ["B2:C30", "D2:E30",
"B2:C30"]
'SeparateInputs'
— Specify separate inputsOption to use each sheet in the Excel file or specified by the
'Sheets'
argument as a separate input, specified as
true
or false
.
input
— Test inputsltest.testmanager.TestInput
object | array of sltest.testmanager.TestInput
objectsTest input, returned as an sltest.testmanager.TestInput
object
or an array of sltest.testmanager.TestInput
objects.
You can add data from a Microsoft Excel spreadsheet. The spreadsheet used in this example is located in the example folder. Add only the two sheets that have data as input.
% Load example model open_system('sltestExcelExample'); % Create new test file tf = sltest.testmanager.TestFile('C:\MATLAB\input_test_file.mldatx'); % Get test suite object ts = getTestSuites(tf); % Get test case object tc = getTestCases(ts); % Add the example model as the system under test setProperty(tc,'Model','sltestExcelExample'); % Add Excel data to Inputs section % Specify two sheets to add: Acceleration and Braking input_path = fullfile(matlabroot,'toolbox','simulinktest',... 'simulinktestdemos','sltestExampleInputs.xlsx'); input = addInput(tc,input_path,'Sheets',["Acceleration","Braking"]); % Map the input signal for the sheets by block name map(input(1),0); map(input(2),0);
This example shows the syntax to add Excel file sheets and range.
% Create test file tf = sltest.testmanager.TestFile('Excel Input Test File'); % Create test suite and test case ts = createTestSuite(tf,'Excel Test Suite'); tc = createTestCase(ts,'baseline','Excel Input Test Case'); % Add Excel data to Inputs section, specifying sheets and range input = addInput(tc,'C:\MyHomeDir\myexcel.xlsx',... 'Sheets',["Optics","Torque","Throttle"],... 'Ranges',["B1:C20","","D1:G10"]);