This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

addInput

Class: sltest.testmanager.TestCase
Package: sltest.testmanager

Add input file to test case

Syntax

input = addInput(tc,file,Name,Value)

Description

input = addInput(tc,file,Name,Value) adds a file to the Inputs section of the test case and returns a test input object, sltest.testmanager.TestInput.

Input Arguments

expand all

Test case that you want to add the test input to, specified as a sltest.testmanager.TestCase object.

Name and path of MAT-file or Microsoft® Excel® input file, specified as a character vector.

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: 'Sheets','mysheet','Ranges','C1:F10','CreateIterations',false

Pairs for MAT-Files and Microsoft Excel Files

expand all

Test case simulation number that the inputs apply to, specified as 1 or 2. This setting applies to equivalence tests.

Example: 'SimulationIndex',2

Option to add the input file to the iteration table under Iterations in the test case, specified as Boolean.

Example: 'CreateIterations',false

Pairs to Use Only with Microsoft Excel Files

expand all

Names 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 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

'Corner1:Corner2'

Rectangular Range

Specify the range using the syntax 'Corner1:Corner2', where Corner1 and Corner2 are two opposing corners that define the region. For example, 'D2:H4' represents the 3-by-5 rectangular region between the two corners D2 and H4 on the worksheet. The 'Range' name-value pair argument is not case-sensitive, and uses Excel A1 reference style (see Excel help).

Example: 'Range','Corner1:Corner2'

''

Unspecified or Empty

If unspecified, the importing function automatically detects the used range.

Example: 'Range',''

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.

'Row1:Row2'

Row Range

You can identify the range by specifying the beginning and ending rows using Excel row designators. Then readtable automatically detects the used column range within the designated rows. For instance, the importing function interprets the range specification '1:7' as an instruction to read all columns in the used range in rows 1 through 7 (inclusive).

Example: 'Range','1:7'

'Column1:Column2'

Column Range

You can identify the range by specifying the beginning and ending columns using Excel column designators. Then readtable automatically detects the used row range within the designated columns. For instance, the importing function interprets the range specification 'A:F' as an instruction to read all rows in the used range in columns A through F (inclusive).

Example: 'Range','A:F'

'NamedRange'

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 'myTable'. If such named ranges exist in a spreadsheet, then the importing function can read that range using its name.

Example: 'Range','myTable'

Example: 'B2:C30', "D2:E30", ["B2:C30", "D2:E30", "B2:C30"]

Option to use each sheet in the Excel file or specified by the 'Sheets' argument as a separate input, specified as true or false.

Output Arguments

expand all

Test input, returned as an sltest.testmanager.TestInput object or an array of sltest.testmanager.TestInput objects.

Examples

expand all

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

Introduced in R2015b