主要内容

自定义测试结果报告

You can choose how to format and aggregate test results by customizing reports. Use thesltest.testmanager.testresultreport类创建子类,然后使用属性和方法来自定义测试管理器如何生成结果报告。您可以更改字体样式,添加图,将结果组织到表中,包括模型图像等。使用自定义类,需要一个MATLAB®报告Generator™license.

继承报告类

To customize the generated report, you must inherit from thesltest.testmanager.testresultreport班级。After you inherit from the class, you can modify the properties and methods. To inherit the class, add the class definition section to a new or existing MATLAB script. The subclass is your custom class name, and the superclass that you inherit from issltest.testmanager.testresultreport. For more information about creating subclasses, see设计子类构造函数. Then, add code to the inherited class or methods to create your customizations.

% class definitionclassdefCustomReport < sltest.testmanager.TestResultReport%% Report customization code here%end

方法层次结构

当您创建子类,派生类herits methods from thesltest.testmanager.testresultreport班级。报告的主体分为三个主要组:结果集块,测试套件结果块和测试用例结果块。

Method hierarchy for report layout

The result set block contains the result set table, the coverage table, and links to the table of contents.

Method hierarchy for result set

测试套件结果块包含测试套件结果表,覆盖范围表,需求链接以及与目录的链接。

测试套件结果的方法层次结构

The test case result block contains the test case and test iterations results table, the coverage table, requirements links, signal output plots, comparison plots, test case settings, and links to the table of contents.

Method hierarchy for test case result

Modify the Class

To insert your own report content or change the layout of the generated report, modify the inherited class methods. For general information about modifying methods, see修改继承的方法.

A simple modification to the generated report could be to add some text to the title page. The method used here isaddTitlePage.

% class definitionclassdefCustomReport < sltest.testmanager.TestResultReport方法功能this = CustomReport(resultObjects, reportFilePath) this@sltest.testmanager.TestResultReport(resultObjects,...reportFilePath);endend方法(Access=protected)功能addTitlePage(obj)导入mlreportgen.dom.*;% Add a custom messagelabel = Text(“可以在这里添加一些自定义内容”);附加(obj.titlepart,标签);%调用超类方法以获取默认行为addTitlePage@sltest.testmanager.TestResultReport(obj);endendend
Click这里for a code file of this example.

A more complex modification of the generated report is to include a snapshot of the model that was tested.

% class definitionclassdefCustomReport < sltest.testmanager.TestResultReport方法功能this = customReport(resultObject,reportfilepath)this@sltest.testmanager.testresultreport(resultObjects,reportfilepath);endend方法(Access=protected)% Method to customize test case/iteration result section in the report功能docpart = gentestcaseresultblock(obj,结果)% result: A structure containing test case or iteration resultimportmlreportgen.dom.*;%调用超类方法以获取默认行为docPart = genTestCaseResultBlock@sltest.testmanager.TestResultReport(...obj,result);% Get the test case result data for putting in the reporttcrObj = result.Data;%在测试案例结果级别插入模型屏幕快照ifisa(tcrobj,'sltest.testmanager.testcaseresult')%初始化型号名称modelName ='';% Check in the test case result if it has model information. If%不,这意味着测试案例或不使用%模型。testsimmetadata = tcrobj.simulationmetadata;if(〜Isempty(testsimmetadata))modelName = testsimmetadata.modelname;end% Get iteration resultsiterResults = getIterationResults(tcrObj);%获取模型名称,以防测试用例有迭代if(~isempty(iterResults)) modelName = iterResults(1).SimulationMetaData.modelName;end% Insert model snapshot. This will not work for harnesses. With%最小变化我们也可以打开用于%测试。if(~isempty(modelName))尝试open_system(modelName); outputFileName = [tempdir, modelName,'.png'];if存在(outputFileName,'file') delete(outputFileName);end打印(outputFileName,'-s','-dpng');para = sltest.testmanager.reportutility.genimageParagraph(...outputfileName,...'5.2in','3.7英寸);附加(Docpart,para);catchendendendendendend
Click这里for a code file of this example.

使用自定义类生成报告

自定义类和方法后,请使用sltest.testmanager.Report生成报告。您必须使用“ CustomReportClass”name-value pair for the custom class, specified as a string. For example:

%从导入数据产生结果结果= sltest.testmanager.importresults('demoresults.mldatx');%指定报告文件名和路径filePath ='TestReport.zip';% Generate the report using the custom classsltest.testmanager.Report(结果,filepath,...'Author','MathWorks',...'标题','Test',...'IncludeMLVersion',true,...'包括',int32(0),...“ CustomReportClass”,“ CustomReport”,...'LaunchReport', true);

Alternatively, you can create your custom report using the Test Manager report dialog box. Select a test result, click theReportbutton on the toolstrip, and specify the custom report class in the Create Test Result Report dialog box. For the Test Manager to use the custom report class, the class must be on the MATLAB path.

See Also

|

相关话题