Main Content

addBaselineCriteria

Class: sltest.testmanager.TestCase
Namespace: sltest.testmanager

Add baseline criteria to test case

Description

example

base = addBaselineCriteria(tc,file) adds a MAT-file, Simulation Data Inspector (SDI) MLDATX file, or Microsoft® Excel® file as baseline criteria to a baseline test case. If file is an Excel file that has multiple sheets, each is added to the test case as a separate baseline set.

example

base = addBaselineCriteria(tc,file,'RefreshIfExists',true) adds the baseline criteria to the test case, replacing the baseline criteria if the test case already had one.

example

base = addBaselineCriteria(tc,excel,'SeparateBaselines',false) adds all sheets in the Excel file as a single baseline set.

example

base = addBaselineCriteria(tc,excel,'Sheets',sheets,Name,Value) specifies the sheets from the Excel to include in the baseline criteria and uses additional options specified by one or more Name,Value pair arguments.

Input Arguments

expand all

Test case that you want to add the baseline criteria to, specified as an sltest.testmanager.TestCase object.

File and pathname of the baseline criteria file, specified as a character vector. You can specify a MAT-file, Simulation Data Inspector MLDATX file, or a Microsoft Excel file.

Example: 'C:\MATLAB\baseline_API.mat'

File and pathname of the Excel file to use as the baseline criteria, specified as a character vector.

Example: 'C:\MATLAB\baseline.xlsx'

Names of sheets from Excel file to add, specified as a character vector, string, or array of strings.

Example: 'signals', ["Heater","Plant"]

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: 'Ranges','B1:C4','RefreshIfExists',false

Ranges of cells from the sheets that you add as baseline criteria, specified as a character vector, a string, or an array of strings. The ranges you specify must correspond to the sheets you specify. 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 to a sheet in the 'Sheets' cell array. Specify an empty range to use the entire sheet.

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

Option to replace the test case baseline criteria, specified as a Boolean. Use false to return an error if the test case already has baseline criteria, that is, to prevent overwriting the baseline. Use true to add the baseline criteria, replacing the existing baseline.

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

Output Arguments

expand all

Baseline criteria added to the test case, returned as an sltest.testmanager.BaselineCriteria object or an array of sltest.testmanager.BaselineCriteria objects.

Examples

expand all

% Open the model for this example
openExample('sldemo_absbrake');

% Create the test file, test suite, and test case structure
tf = sltest.testmanager.TestFile('API Test File');
ts = createTestSuite(tf,'API Test Suite');
tc = createTestCase(ts,'baseline','Baseline API Test Case');

% Remove the default test suite
tsDel = getTestSuiteByName(tf,'New Test Suite 1');
remove(tsDel);

% Assign the system under test to the test case
setProperty(tc,'Model','sldemo_absbrake');

% Add baseline criteria from file
baseline = addBaselineCriteria(tc,'C:\MATLAB\baseline_API.mat');

Use an Excel file as baseline, overwriting the existing baseline on the test case.

% Open the model for this example
openExample('sldemo_absbrake');

% Create the test file, test suite, and test case structure
tf = sltest.testmanager.TestFile('Excel Test File');
ts = createTestSuite(tf,'Excel Test Suite');
tc = createTestCase(ts,'baseline','Baseline Excel Test Case');

% Remove the default test suite
tsDel = getTestSuiteByName(tf,'New Test Suite 1');
remove(tsDel);

% Assign the system under test to the test case
setProperty(tc,'Model','sldemo_absbrake');

% Add baseline criteria from file
baseline = addBaselineCriteria(tc,...
   'C:\MATLAB\myexcel.xlsx','RefreshIfExists',true);

Use an Excel file as baseline, creating one baseline even if the Excel file has multiple sheets.

% Open the model for this example
openExample('sldemo_absbrake');

% Create the test file, test suite, and test case structure
tf = sltest.testmanager.TestFile('Excel Test File');
ts = createTestSuite(tf,'Excel Test Suite');
tc = createTestCase(ts,'baseline','Baseline Excel Test Case');

% Remove the default test suite
tsDel = getTestSuiteByName(tf,'New Test Suite 1');
remove(tsDel);

% Assign the system under test to the test case
setProperty(tc,'Model','sldemo_absbrake');

% Add baseline criteria from file
baseline = addBaselineCriteria(tc,...
   'C:\MATLAB\myexcel.xlsx','SeparateBaselines',false);

Select three sheets from an Excel file to use as the baseline. For each sheet, specify a range of cells.

% Open the model for this example
openExample('sldemo_absbrake');

% Create the test file, test suite, and test case structure
tf = sltest.testmanager.TestFile('Excel Test File');
ts = createTestSuite(tf,'Excel Test Suite');
tc = createTestCase(ts,'baseline','Baseline Excel Test Case');

% Remove the default test suite
tsDel = getTestSuiteByName(tf,'New Test Suite 1');
remove(tsDel);

% Assign the system under test to the test case
setProperty(tc,'Model','sldemo_absbrake');

% Create sheets and ranges arrays
sheets = ["HotTemp", "ColdTemp", "NominalTemp"];
ranges = ["B2:C30", "D2:E30", "B2:C30"];

% Add baseline criteria from file, using the sheets and cell ranges specified
baseline = addBaselineCriteria(tc,...
   'C:\MATLAB\myexcel.xlsx','Sheets',sheets,'Ranges',ranges);

Version History

Introduced in R2015b