Main Content

Create and Run Test Cases with Scripts

For a list of functions and objects in the金宝app®Test™programmatic interface, seeTest Scripts

创建并运行基线测试用例

此示例显示了如何使用sltest.testmanager自动化测试和生成报告的功能,类和方法。您可以创建测试用例,编辑测试案例标准,运行测试案例,导出仿真输出并以编程方式生成结果报告。该示例将模型的仿真输出与基线进行了比较。

% Open the model for this exampleopenExample('sldemo_absbrake');%创建测试文件,测试套件和测试案例结构tf = sltest.testmanager.testfile('API Test File');ts = createTestSuite(tf,'API Test Suite');tc = createTestcase(ts,'baseline',,,,“基线API测试案例”);% Remove the default test suitetsdel = getTestSuiteByName(tf,“新测试套件1”);删除(tsdel);%将正在测试的系统分配给测试案例SetProperty(TC,'Model',,,,'sldemo_absbrake');% Capture the baseline criteriabaseline = captureBaselineCriteria(tc,'baseline_API.mat',真的);%通过在测试用例中覆盖新模型参数来测试新模型参数%参数集ps = addParameterSet(tc,'姓名',,,,“ API参数集”);po = addParameterOverride(ps,'m',,,,55);%设置一个信号的基线标准公差sc = getsignalCriteria(基线);sc(1).abstol = 9;%运行测试用例和结果返回一个对象lts dataResultsObj = run(tc);% Get the test case result and the Sim Output run datasettcr = getTestCaseResults(ResultsObj); runDataset = getOutputRuns(tcr);%打开测试管理器,因此您可以查看模拟% output and comparison datasltest.testmanager.view;%从结果数据中生成报告filepath ='test_report.pdf';sltest.testmanager.Report(ResuctesObj,filepath,...'作者',,,,“测试工程师”,,,,...'IncludeSimulationSignalPlots',真的,...“包含eComparisSignAlplots',真的);%导出SIM模拟输出运行数据集dataset = export(rundataset);

测试案例失败了,因为模拟输出和基线标准之间的一个信号比较之一在公差之内。结果报告是PDF,并在完成后打开。有关更多报告生成设置,请参阅sltest.testmanager。report功能参考页。

Create and Run an Equivalence Test Case

此示例比较两个模拟之间的信号数据以测试等效性。

% Open the model for this exampleopenExample('sldemo_absbrake');%创建测试文件,测试套件和测试案例结构tf = sltest.testmanager.testfile('API Test File');ts = createTestSuite(tf,'API Test Suite');tc = createTestcase(ts,'等价',,,,“等效测试案例”);% Remove the default test suitetsdel = getTestSuiteByName(tf,“新测试套件1”);删除(tsdel);%将正在测试的系统分配给测试案例% for Simulation 1 and Simulation 2SetProperty(TC,'Model',,,,'sldemo_absbrake',,,,“仿真index”,1);SetProperty(TC,'Model',,,,'sldemo_absbrake',,,,“仿真index”,2);% Add a parameter override to Simulation 1 and 2PS1 = AddParameterset(TC,'姓名',,,,'参数集1',,,,“仿真index”,1);po1 = addParameterOverride(PS1,'rr',1.20);PS2 = AddParameterset(TC,'姓名',,,,“参数集2”,,,,“仿真index”,2);PO2 = AddParameterOverride(PS2,'rr',1.24);%捕获等效标准EQ = Capture EquivalCriteria(TC);% Set the equivalence criteria tolerance for one signalsc = getSignalCriteria(eq); sc(1).AbsTol = 2.2;%运行测试用例和结果返回一个对象lts dataResultsObj = run(tc);%打开测试管理器,因此您可以查看模拟% output and comparison datasltest.testmanager.view;

在测试管理器结果的等效标准结果部分中,yout.Ww信号由于公差值而通过。其他信号比较不会通过,总体测试案例失败。

运行测试案例并收集覆盖范围

此示例显示了如何使用仿真测试案例收集覆盖范围结果。要收集覆盖范围,您需要一个金宝appSimulink Coverage™执照。

% Open the model for this exampleopenExample('SLDEMO_AUTOTRANS');%创建测试文件,测试套件和测试案例结构tf = sltest.testmanager.testfile('API Test File');ts = createTestSuite(tf,'API Test Suite');tc = createTestcase(ts,'模拟',,,,'Coverage Test Case');% Remove the default test suitetsdel = getTestSuiteByName(tf,“新测试套件1”);删除(tsdel);%将正在测试的系统分配给测试案例SetProperty(TC,'Model',,,,'SLDEMO_AUTOTRANS');%在测试文件级别打开覆盖范围设置cov = getCoveragesettings(tf);cov.recordCoverage = true;%启用MCDC和信号范围覆盖率指标cov.metricsettings ='mr';%运行测试用例和结果返回一个对象lts datars = run(tf);%获得覆盖结果cr = getCoverageresults(rs);% Open the Test Manager to view resultssltest.testmanager.view;

In the结果和工件测试经理的窗格,单击结果。您可以查看汇总覆盖结果。

Create and Run Test Case Iterations

This example shows how to create test iterations. You can create table iterations programmatically that appear in the迭代测试案例的部分。该示例创建了模拟测试案例,并为每次迭代分配一个信号编辑器方案。

% Open the model for this exampleopenExample('SLDEMO_AUTOTRANS');% Create test file, test suite, and test case structuretf = sltest.testmanager.testfile('Iterations Test File');ts = getTestSuites(tf);tc = createTestcase(ts,'模拟',,,,'Simulation Iterations');% Specify model as system under testSetProperty(TC,'Model',,,,'SLDEMO_AUTOTRANS');% Set up table iteration%创建迭代对象testItr1 = sltestiteration;%设置迭代设置settestparam(testitr1,“ SignalDitorScenario”,,,,'Passing Maneuver');% Add the iteration to test case添加器(TC,TestItr1);%设置另一个桌子迭代%创建迭代对象testItr2 = sltestiteration;%设置迭代设置settestparam(testitr2,“ SignalDitorScenario”,,,,“海岸”);% Add the iteration to test case添加器(TC,TestItr2);% Run test case that contains iterations结果=运行(TC);%获得迭代结果tcresults = getTestCaseresults(结果);iterResults = getIterationResults(tcresults);

Related Topics