Customize Test Results Reports
You can choose how to format and aggregate test results by customizing reports. You can customize the report by using a custom class, a custom template file, or a combination of both. The custom class controls the content and the formatting of the output from Simulink® Test™, while the custom template file controls the content and the formatting of the report file. For example, you can use a custom class to only include failed tests in the report or to make the test results a certain font size. You can use a custom template file to add a cover page with custom text and control the font of that custom text.
Customize Reports Using a Custom Class
Use the sltest.testmanager.TestResultReport
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.
To customize the generated report, you must inherit from the sltest.testmanager.TestResultReport
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 Design Subclass Constructors. Then, add code to the
inherited class or methods to create your customizations.
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.
Customize Reports Using a Custom Template File
You can generate reports as HTML, PDF, or DOCX files. You can customize the template files for the reports to add content, remove content, change the formatting, or change the section ordering of a report. For more information about customizing template files, see Modify Styles in Microsoft Word Templates (MATLAB Report Generator), Modify Styles in HTML Templates (MATLAB Report Generator), and Modify Styles in PDF Templates (MATLAB Report Generator).
Customize a Test Results Report
This example shows how to customize a test results report by using a custom class, a custom template file, or a combination of both.
Use a Custom Class to Customize a Test Results Report
You can customize your report by creating a subclass of the sltest.testmanager.TestResultReport
and modifying the methods and properties. You can change the report title, plots, tables, headers, icons, and other aspects of the report. This example has a custom class file called CustomReport
that includes modified properties and methods.
To customize the class, define a new class and inherit from the sltest.testmanager.TestResultReport
class. In this example, the new class is CustomReport
.
classdef CustomReport < sltest.testmanager.TestResultReport
To modify properties with protected SetAccess
, add a class constructor method to the newly defined class. Then set the values of the properties you want to change. In this example, CustomReport
changes the body font size to 11 pt.
methods function this = CustomReport(resultObjects, reportFilePath) this@sltest.testmanager.TestResultReport(resultObjects,reportFilePath); this.BodyFontSize = "11pt"; end end
To modify properties with public SetAccess
, when generating the report programmatically, include the property name and new value in your sltest.testmanager.report
command. Alternatively, when generating the report with the Test Manager, specify the values of these properties in the Create Test Results Report window.
To change or add content to the report, modify the inherited class methods. In this example, CustomReport
modifies the addTitlePage
method to include a custom label on the title page of the report.
methods(Access=protected) function addTitlePage(obj) import mlreportgen.dom.*; % Call the superclass method to get the default behavior addTitlePage@sltest.testmanager.TestResultReport(obj); % Add a custom message label = Text("Some custom content can be added here"); append(obj.TitlePart,label); end end
Additionally, lines 10 through 66 in CustomReport
modify the genTestCaseResultBlock
method to add a model screenshot.
Use a Custom Template File to Customize a Test Results Report
You can also use a custom template file to customize the report. To customize a PDF template file, follow these steps:
1. To access the template file, unzip the PDF template file.
unzip('dCustomReportTemplate_pdf_sample1.pdftx');
Unzipping the file creates a root.html
file and a /stylesheets/root.css
file in the new CustomReportTemplate_pdf_sample1
folder.
2. Open and edit the root.html
file using a text editor. This file lists the content holes in the order in which the content appears in the report. In this file, you can reorder the report sections and delete template holes.
3. In the stylesheets
folder, open and edit the root.css
file using a text editor. In this file, you can change the table borders, font size, text color, and other styles for content added in the root.html
file. To learn more about modifying report styles, see Modify Styles in PDF Templates (MATLAB Report Generator).
4. Zip the files into the dCustomReportTemplate_pdf_sample1.pdftx
file.
zipTemplate('dCustomReportTemplate_pdf_sample1.pdftx');
For information on customizing Word or HTML templates, see Modify Styles in Microsoft Word Templates (MATLAB Report Generator) or Modify Styles in HTML Templates (MATLAB Report Generator), respectively.
The default PDF report uses this HTML code:
<html> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <title>Report Template</title> <link rel="StyleSheet" href="./stylesheets/root.css" type="text/css" /> </head> <body> <hole id="ChapterTitle"/> <pagebreak/> <hole id="ChapterTOC"/> <pagebreak/> <hole id="ChapterBody"/> </body> </html>
The template file in this example modifies the HTML code in the <body>
section of the root.html
file to add page numbers, a cover page with the MathWorks logo, a table, and custom text.
This code adds the page numbers:
<layout style="page-margin: 1in 1in 1in 1in 0.5in 0.5in 0in; page-size: 8.5in 11in portrait" > <pfooter template-name="Footer"> </pfooter> <pnumber initial-value="1" format="1" /> </layout>
This code adds the logo:
<div align="center"> <img src="./images/bg_global_logo.png" height="40px" width="40px"/> <img src="./images/bg_h1_matlab.png" /> </div>
This code adds the title for the table:
<h1 align="center">Information captured in this report</h1>
The code in lines 23 through 82 adds the table. This table is hard-coded and does not reflect the content of the test results report. However, it is an example of how to create a table in the template file.
This code adds the custom text:
<br/><br/> <span class="loremipsum"> Lorem ipsum dolor sit amet. </span>
Generate Customized Test Results Report
You can generate the test results report programmatically or by using the Test Manager interface.
To generate the report programmatically:
1. Load and run the tests in Test Manager.
exampleFile = 'sltestTestManagerReportsTestSuite.mldatx';
sltest.testmanager.load(exampleFile);
results = sltest.testmanager.run;
2. Specify the file name and extension for the report.
filePath = 'Report.pdf';
3. Generate the report using the custom class and custom template file. You can also modify other properties with public SetAccess
, such as IncludeCoverageResult
, as name-value arguments.
sltest.testmanager.report(results,filePath,... IncludeTestResults=0, ... IncludeComparisonSignalPlots=true, ... IncludeSimulationSignalPlots=true, ... NumPlotRowsPerPage=3, ... CustomReportClass="CustomReport", ... IncludeCoverageResult=true,... CustomTemplateFile="dCustomReportTemplate_pdf_sample1.pdftx")
To generate the report by using the Test Manager:
1. Double-click on the test file, sltestTestManagerReportsTestSuite.mldatx
, in the current folder to open it in the Test Manager.
2. In the left pane, select the test suite. Click Run.
3. In the left pane, select the test results. In the toolstrip, click Report.
4. In the Customization section of the Create Test Result Report dialog box, click on the folder icon next to Template File.
5. Navigate to the 'dCustomReportTemplate_pdf_sample1.pdftx'
file and click Open.
6. Set Report Class to CustomReport
, which is the name of the custom class. You can also modify properties with public SetAccess
, such as Coverage Results, in this window.
7. Click Create.
See Also
sltest.testmanager.TestResultReport
| sltest.testmanager.report