您可以创建与持续集成(CI)系统(如Jenkins™)兼容的模型测试。要创建与ci兼容的结果,请运行您的金宝app®TEST™使用MATLAB文件®单元测试。
要运行CI兼容的测试,请按照此一般程序进行操作:
从MLDATX测试文件创建测试套件。
创建一个测试赛道。
为测试输出或覆盖结果创建插件。
对于模型覆盖范围,使用modelcoverageplugin.
和CoberturaFormat
.在收集Cobertura格式的模型覆盖率时:
只有顶级模型覆盖率被反映在Cobertura XML中。
只反映model Decision覆盖范围,并将其映射到Cobertura XML中的Condition元素。
为CI兼容输出创建插件。
将插件添加到测试输出或覆盖结果。
将测试输出插件或覆盖结果插件添加到Test Runner。
运行测试。
这个例子展示了如何测试一个模型,发布test Manager结果,并通过一次执行以TAP格式输出结果。
您使用MATLAB®单元测试创建测试套件和测试赛道,并使用这些插件自定义RINNER:
matlab.unittest.plugins.testreportplugin.
生成MATLAB测试报告。
sltest.plugins.testmanagerresultsplugin.
将测试管理器添加到Matlab测试报告。
matlab.unittest.plugins.tapplugin.
将结果输出到点按文件。
测试用例为控制器子系统创建一个方波输入,并扫过25个参数迭代一种
和B.
.测试比较了α
输出到具有容差的基线0.0046
.在那些输出超过此容忍值的迭代上测试失败。
在运行此示例之前,请确保工作文件夹可写。
1.打开Simulin金宝appk®Test™测试文件。
testfile = fullfile('f14parametersweeptest.mldatx');sltest.testmanager.view;sltest.testmanager.load(testfile);
2.在“测试管理器”中,配置用于报告的测试文件。
在下面测试文件选项, 选择执行后生成报告.该部分展开,显示几个报表选项。有关更多信息,请参见使用测试文件保存报告选项.
3.从Simulink®test™测试文件创建测试套件。金宝app
进口matlab.unittest.testsuite.套房= testsuite('f14parametersweeptest.mldatx');
4.创建一个测试赛道。
进口matlab.unittest.TestRunnerf14runner = testrunner.withnoplugins;
5.添加testreportplugin.
到测试赛道。
该插件产生了MATLAB测试报告f14report.pdf.
.
进口matlab.unittest.plugins.testreportplugin.pdffile ='f14report.pdf';TRP = TESTREPORTPLUGIN.PRODONTEPDF(PDFFILE);AddPlugin(F14Runner,TRP)
6.添加TestManagerResultsPlugin
到测试赛道。
插件将测试管理器添加到Matlab测试报告。
进口sltest.plugins.testmanagerresultsplugin.咯= TestManagerResultsPlugin;addPlugin (f14runner咯)
7.添加TAPPlugin
到测试赛道。
插件输出到f14output.tap.
文件。
进口matlab.unittest.plugins.tapplugin.进口matlab.unittest.plugins.tofile.tapFile ='f14output.tap';利用= TAPPlugin.producingVersion13(去整理(tapFile));addPlugin (f14runner,挖掘)
8.运行测试。
几个迭代失败,其中信号基线差超过公差标准。
结果= run(f14runner,套件);
生成测试报告。请稍等。为测试报告准备内容。
向测试报告添加内容。将测试报告写入文件。测试报告已经被保存到:/tmp/Bdoc21a_1622859_255720/tpdb9024e8/simulinktest-ex40056金宝app435/F14Report.pdf
测试运行程序的一次执行产生两个报告:
包含测试管理器结果的MATLAB测试报告。
可以与CI系统一起使用的TAP格式文件。
sltest.testManager.ClearResults SLTEST.TestManager.clear sltest.testManager.Close.
此示例显示如何为连续集成生成模型覆盖结果。Cobertura格式报告了覆盖范围。您使用Matlab®金宝app单元测试运行Simulink®IST™测试文件。
1.导入类并从测试文件创建测试套件autopilottestfile.mldatx.
.
进口matlab.unittest.TestRunneraptest = sltest.testManager.Testfile(“AutopilotTestFile.mldatx”);apsuite = testsuite (aptest.FilePath);
2.创建测试赛道。
紫= TestRunner.withNoPlugins;
3.将覆盖度量设置为收集。此示例使用决策覆盖范围。在Cobertura产出中,决策覆盖范围列为条件元素。
进口sltest.plugins.coverage.CoverageMetrics.cmet =覆盖术('决定',真的);
4.设置覆盖报告属性。这个示例生成一个文件R13Coverage.xml
在当前工作文件夹中。确保您的工作文件夹具有写权限。
进口sltest.plugins.coverage.modelcoveragreeport.进口matlab.unittest.plugins.codecoverage.coberturaformatrptfile =“R13Coverage.xml”;RPT = COBERTURAFORMAT(RPTFILE)
rpt = CoberturaFormat没有属性。
5.创建一个模型覆盖插件。插件收集覆盖率指标并生成Cobertura格式报告。
进口sltest.plugins.modelcoveragepluginmcp = modelcoverageplugin(“收集”,cmet,“生产”rpt)
mcp = ModelCoveragePlugin with properties: RecordModelReferenceCoverage: '' MetricsSettings: [1x1 sltest.plugin .coverage. coveragemetrics]
6.将Coverage插件添加到Test Runner中。
mcp addPlugin(紫)%关闭命令行警告:警告从Stateflow: cdr: VerifyDangerousComparison警告从StateFlow:运行时:测试验证措施
7.运行测试。
Apresult = run(trun,apsuite)
APResult = TestResult with properties: Name: 'AutopilotTestFile > Basic Design Test Cases/ requirements 1.3 Test' Passed: 0 Failed: 1 Incomplete: 0 Duration: 4.5704 Details: [1x1 struct]总计:0 Passed, 1 Failed, 0 Incomplete. 4.5704 seconds Test time.测试时间。
8.可重新启动。
警告在Stateflow: cdr: VerifyDangerousComparison警告在StateFlow:运行时:测试验证措施
matlab.unittest.plugins.tapplugin.
|matlab.unittest.plugins.testreportplugin.
|sltest.plugins.modelcoverageplugin
|sltest.plugins.testmanagerresultsplugin.
|TestRunner.
|testsuite.