Main Content

本页采用了机器翻译。点击此处可查看英文原文。

addBaselineCriteria

类: sltest.testmanager.TestCase
命名空间: sltest.testmanager

将基线准则添加到测试用例

说明

示例

base = addBaselineCriteria(tc,file) 将 MAT 文件、仿真数据检查器 (SDI) MLDATX 文件或 Microsoft® Excel® 文件作为基线准则添加到基线测试用例。如果 file 是具有多个工作表的 Excel 文件,则每个工作表都会作为单独的基线集添加到测试用例中。

示例

base = addBaselineCriteria(tc,file,'RefreshIfExists',true) 将基线准则添加到测试用例中,如果测试用例已经有基线准则,则用其替换基线准则。

示例

base = addBaselineCriteria(tc,excel,'SeparateBaselines',false) 将 Excel 文件中的所有工作表添加为单个基线集。

示例

base = addBaselineCriteria(tc,excel,'Sheets',sheets,Name,Value) 指定要包含在基线准则中的 Excel 表,并使用一个或多个 Name,Value 对参量指定的附加选项。

输入参数

全部展开

您想要添加基线准则的测试用例,指定为 sltest.testmanager.TestCase 对象。

基线准则文件的文件和路径名,指定为字符向量。您可以指定 MAT 文件、Simulation Data Inspector MLDATX 文件或 Microsoft Excel 文件。

示例: 'C:\MATLAB\baseline_API.mat'

用作基线准则的 Excel 文件的文件和路径名,指定为字符向量。

示例: 'C:\MATLAB\baseline.xlsx'

要添加的 Excel 文件中的工作表的名称,指定为字符向量、字符串或字符串数组。

示例: 'signals', ["Heater","Plant"]

名称-值参数

将可选的参量对组指定为 Name1=Value1,...,NameN=ValueN,其中 Name 是参量名称,Value 是对应的值。名称-值参量必须出现在其他参量后,但参量对组的顺序无关紧要。

在 R2021a 之前,使用逗号分隔每个名称和值,并用引号将 Name 引起来

示例: 'Ranges','B1:C4','RefreshIfExists',false

您添加为基线准则的工作表中的单元格范围,指定为字符向量、字符串或字符串数组。您指定的范围必须与您指定的工作表相对应。例如,如果指定一张工作表,则指定一个范围。如果指定工作表的元胞数组,则 'Ranges' 元胞数组中的每个值必须与 'Sheets' 元胞数组中的一个工作表相对应。指定一个空范围以使用整个工作表。

示例: 'B2:C30', "D2:E30", ["B2:C30", "D2:E30", "B2:C30"], ["B2:C30","","D2:E30"]

用于替换测试用例基线准则,指定为布尔值。如果测试用例已经有基线准则,则使用 false 返回错误,即防止覆盖基线。使用 true 添加基线准则,替换现有的基线。

选择使用 'Sheets' 参量指定的每个工作表作为单独的基线,指定为 truefalse

输出参量

全部展开

添加到测试用例的基线准则,以 sltest.testmanager.BaselineCriteria 对象或 sltest.testmanager.BaselineCriteria 对象数组的形式返回。

示例

全部展开

% 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');

使用 Excel 文件作为基线,覆盖测试用例上现有的基线。

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

使用 Excel 文件作为基线,即使 Excel 文件有多张表,也创建一个基线。

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

从 Excel 文件中选择三张表作为基线。对于每个工作表,指定一个单元格范围。

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

版本历史记录

在 R2015b 中推出