customize test results reports
you can choose how to format and aggregate test results by customizing reports. use the class to create a subclass and then use the properties and methods to customize how the test manager generates the results report. you can change font styles, add plots, organize results into tables, include model images, and more. using the custom class, requires a matlab® report generator™ license.
inherit the report class
to customize the generated report, you must inherit from the class. 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 is sltest.testmanager.testresultreport
. for more information about
creating subclasses, see . then, add code to the
inherited class or methods to create your
customizations.
% class definition classdef customreport < sltest.testmanager.testresultreport % % report customization code here % end
method hierarchy
when you create the subclass, the derived class inherits methods from the sltest.testmanager.testresultreport
class. the body of
the report is separated into three main groups: the result set block, the test suite
result block, and the test case result block.
the result set block contains the result set table, the coverage table, and links to the table of contents.
the test suite result block contains the test suite results table, the coverage table, requirements links, and links to the table of contents.
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.
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 is addtitlepage
.
% class definition classdef customreport < sltest.testmanager.testresultreport methods function this = customreport(resultobjects, reportfilepath) this@sltest.testmanager.testresultreport(resultobjects,... reportfilepath); end end methods(access=protected) function addtitlepage(obj) import mlreportgen.dom.*; % add a custom message label = text('some custom content can be added here'); append(obj.titlepart,label); % call the superclass method to get the default behavior addtitlepage@sltest.testmanager.testresultreport(obj); end end end
a more complex modification of the generated report is to include a snapshot of the model that was tested.
% class definition classdef customreport < sltest.testmanager.testresultreport methods function this = customreport(resultobjects,reportfilepath) this@sltest.testmanager.testresultreport(resultobjects,reportfilepath); end end methods(access=protected) % method to customize test case/iteration result section in the report function docpart = gentestcaseresultblock(obj,result) % result: a structure containing test case or iteration result import mlreportgen.dom.*; % call the superclass method to get the default behavior docpart = gentestcaseresultblock@sltest.testmanager.testresultreport(... obj,result); % get the test case result data for putting in the report tcrobj = result.data; % insert model screenshot at the test case result level if isa(tcrobj, 'sltest.testmanager.testcaseresult') % initialize model name modelname = ''; % check in the test case result if it has model information. if % not, it means there were iterations in the test case or a % model was not used. testsimmetadata = tcrobj.simulationmetadata; if (~isempty(testsimmetadata)) modelname = testsimmetadata.modelname; end % get iteration results iterresults = getiterationresults(tcrobj); % get the model name in case test case had iterations if (~isempty(iterresults)) modelname = iterresults(1).simulationmetadata.modelname; end % insert model snapshot. this will not work for harnesses. with % minimal changes we can also open the harness used for % testing. if (~isempty(modelname)) try open_system(modelname); outputfilename = [tempdir, modelname, '.png']; if exist(outputfilename,'file') delete(outputfilename); end print(outputfilename, '-s', '-dpng'); para = sltest.testmanager.reportutility.genimageparagraph(... outputfilename,... '5.2in','3.7in'); append(docpart,para); catch end end end end end end
generate a report using the custom class
after you customize the class and methods, use the to generate the report. you must use the
'customreportclass'
name-value pair for the custom class,
specified as a string. for
example:
% generate the result set from imported data result = sltest.testmanager.importresults('demoresults.mldatx'); % specify the report filename and path filepath = 'testreport.zip'; % generate the report using the custom class sltest.testmanager.report(result,filepath, ... 'author','mathworks',... 'title','test',... 'includemlversion',true,... 'includetestresults',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 the report button 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
|