clear
modelname=bdroot;%获取当前打开的模型
sltest.testmanager.clear;%清除测试管理文件
tf=sltest.testmanager.TestFile('testfile');%创建测试管理文件
ts=createTestSuite(tf,'testsuite_for_testmanager');%创建测试集
tc=createTestCase(ts,'baseline','BaselineSimulation');%创建测试用例,测试用例是基于baseline建立的
setProperty(tc,'Model',modelname);%设为当前模型
setProperty(tc,'SaveInputRunInTestResult',true)
setProperty(tc,'SaveBaselineRunInTestResult',true);
setProperty(tc,'StopSimAtLastTimePoint',true);
%删除预定义的测试case
tsDel = getTestSuiteByName(tf,"New Test Suite 1");
remove(tsDel);
sltest.testmanager.view%显示测试管理界面
%获取模型费盖度
covSettings= getCoverageSettings(tf);
covSettings.RecordCoverage=true;
covSettings.MdlRefCoverage=true;
%Enable McDC and sinal range coverage netrics
covSettings.MetricSettings='dcm';%首字母
%Specity a coverage filter I
covSettings.CoverageFilterFilename ='covfilter.cvf';
%打开软件,编辑,at文件
%MeignalEaltor
%加载到测试文件
curpath=pwd;%设置测试模型为当前打开模型
input(1)=addInput(tc,[curpath 'D:\Project\MATLABPro\ExcelTest\myexcel.xlsx'],'CreateIterations' ,false);
%input(1)=addInput(tc,[curpath '\mymat.mat'],'Createlterations' ,false);
map(input(1),0);
%map(input(2),0);
%Add baseline crineria from file
baseline=addBaselineCriteria(tc,'D:\Project\MATLABPro\ExcelTest\myexcel_bs.xlsx');
%baseline=addBaselineCriteria(tc,'\mymat_bs.mat');
sc=getSignalCriteria(baseline);
sc(1).InterpMethod='zoh';%连接保持
%添加sil测试case
equivalenceTc=createTestCase(ts,'equivalence','Equivalence Test Case');
setProperty(equivalenceTc,'Model',modelname,'SimulationIndex',1);
setProperty(equivalenceTc,'Model',modelname,'SimulationIndex',2);
setProperty(equivalenceTc,'SimulationMode','Normal','SimulationIndex',1);
setProperty(equivalenceTc,'SimulationMode','Software-in-the-Loop (SIL)','SimulationIndex',2);
input_sim1(1)=addInput(equivalenceTc,[curpath 'D:\Project\MATLABPro\ExcelTest\myexcel.xlsx'],'SimulationIndex',1,'CreateIterations',false);
map(input_sim1(1),0);
input_sim2(1)=addInput(equivalenceTc,[curpath 'D:\Project\MATLABPro\ExcelTest\myexcel.xlsx'],'SimulationIndex',2,'CreateIterations',false);
map(input_sim2(1),0);
%运行测试
result=sltest.testmanager.run;
%生成测试报告
%result = sltest.testmanager.importResults('testResults.mldatx');
sltest.testmanager.report(result,'testreport.pdf',...
'Author','leith',...
'Title','UnitTestReport',...
'IncludeMLVersion',true,...
'IncludeTestResults',int32(1),...
'NumPlotColumnsPerPage',2,...
'LaunchReport',true);%生成后是否打开报告