Customize Test Specification Reports
You can customize test specification reports by creating a new test case or test suite template or reporter. The test suite templates and reporter are used for both test suites and test files.
To remove content or change the formatting or section ordering of a report, create a new template. To add new content, create a new reporter and specify new holes to hold that content.
Note
To customize a report, you must have a Simulink® Report Generator™ license.
Remove Content or Change Report Formatting and Section Ordering
To change the formatting or section ordering of a Test Specification Report or to
remove content, use the createTemplate
method of the
TestCaseReporter
or TestSuiteReporter
. The
createTemplate
method applies to one output type at a time
(PDF, HTML, or Word).
This example creates a new test case reporter template for PDF output. The process is the same for creating templates for other output types and for creating test suite reporter templates.
Create a copy of the default
TestCaseReporter
PDF template in the current working folder. This folder must be writable. In this case, the folder name ismyCustomTCTemplate
.Forsltest.testmanager.TestCaseReporter.createTemplate(... 'myCustomTCTemplate','pdf');
pdf
andzip
(zip
is used for HTML) output,createTemplate
creates a zipped file.docx
(Word) output it creates a.dotx
template file.To access the separate template files, unzip the PDF template file.
Unzipping the file creates aunzipTemplate('myCustomTCTemplate.pdftx');
docpart_templates.html
file and a/stylesheets/root.css
file in the newmyCustomTCTemplate
folder. PDF and HTML reports use HTML template files.Open and edit the
docpart_templates.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. A portion of thedocpart_templates.html
file is shown.In the
stylesheets
folder, open and edit theroot.css
file using a text editor. In this file, you can change the table borders, font size, text color, and other styles. For example, to set a font size to 14 pixels, usefont-size: 14px;
To learn more about modifying report styles, see Modify Styles in PDF Templates (MATLAB Report Generator). For information on Word or HTML styles, see Modify Styles in Microsoft Word Templates (MATLAB Report Generator) or Modify Styles in HTML Templates (MATLAB Report Generator), respectively.
Zip the files into to the
myCustomTCTemplate.pdftx
file.zipTemplate('myCustomTCTemplate.pdftx');
Use the custom template for your test specification PDF report by using either of these processes.
Use
sltestmgr
to open the Test Manager and click Test Spec Report to open the Create a Test Specification Report dialog box. AddmyCustomTCTemplate.pdftx
to the Test Case Reporter field.Specify the
myCustomTCTemplate.pdftx
filename in theTestCaseReporterTemplate
property of thesltest.testmanager.TestSpecReport
.sltest.testmanager.TestSpecReport(test_cases,'testReport.pdf',... 'Author','John Smith','Title','Autopilot Test Spec Report',... 'LaunchReport',true,... 'TestCaseReporterTemplate','MyCustomTCTemplate.pdftx')
Add Content to a Test Specification Report
To add new content to a report or override how content is added, create a subclass
of the sltest.testmanager.TestCaseReporter
or
sltest.testmanager.TestSuiteReporter
class. Then add properties
and methods for the new content in its class definition file. Add holes to hold that
content in the test suite or test case templates.
This example describes creating a new test case reporter. Use the same process to create a new test suite reporter.
To create a new test case reporter class, use the
customizeReporter
method of theTestCaseCreate
reporter class. This command creates a new class folder in the current working folder. This new reporter inherits from theTestCaseReporter
class.See Subclass Reporter Definitions (MATLAB Report Generator).customTCRptr = ... sltest.testmanager.TestCaseReporter.customizeReporter... ('@myTCReporter');
The
@myTCReporter
folder has amyTCReporter.m
class definition file and aresources
folder. Theresources
folder contains atemplates
folder, which contains folders and files for the report output types:pdf
folderdefault.pdftx
— Zipped PDF template file. Unzip this file usingunzipTemplate
(MATLAB Report Generator) and then open the template file using a text editor. After editing, usezipTemplate
(MATLAB Report Generator).
docx
folderdefault.dotx
— Word template file. Open this template file by right-clicking and selecting Open from the context menu. If you click the filename to open it, the Word file associated with the template opens instead of the template file. See Open Template Files (MATLAB Report Generator).
html
folderdefault.htmt
— Single-file HTML template. Open this file using a text editor.default.htmtx
— Zipped HTML template file. Unzip this file usingunzipTemplate
(MATLAB Report Generator) and then open the template file using a text editor. After editing, usezipTemplate
(MATLAB Report Generator).
For information on templates, see Templates (MATLAB Report Generator).
In the
@myTCReporter
folder, open the class definition filemyTCReporter.m
in a text editor.To add new content, add a
property
and define aget<property>
method in the customized class definition file. Then add the hole to the output type templates.For example, for a new section named References, add a
References
property and define agetReferences
method in themyTCReporter.m
class definition file.Then, add
<hole id="References">REFERENCES</hole>
to the template files in the desired location to include the hole content in the generated report for each output type. See Add Holes in HTML and PDF Templates (MATLAB Report Generator) and Add Holes in Microsoft Word Templates (MATLAB Report Generator).To override an existing method, add a function in the customized class definition file that defines the
get
method for the hole.For example, for the
TestDetails
hole in theTestCaseReporter
, create a method calledgetTestDetails
in the customizedTestCaseReporter
class definition file. You do not need to add a property or hole because they are already specified in theTestCaseReporter
class from which the customized reporter inherits.To generate a report using the custom reporter, use Simulink Report Generator commands (see Define New Reporters (MATLAB Report Generator)).
These sample commands create a PDF report for a test case. It uses the
myTCReporter
reporter, which takes a test case array (test_cases
) as the input object. Then, add the test case reporter object to the report and userptview
(MATLAB Report Generator) to display it. The report is saved in themyCustomTestSpecRpt.pdf
file.myrpt = slreportgen.report.Report('myCustomTestSpecRpt.pdf'); testcaseRptr = myTCReporter('Object',test_cases); add(myrpt,testcaseRptr); close(myrpt); rptview(myrpt);
Related Topics
- Customize Test Results Reports
- Templates (MATLAB Report Generator)
- Open Template Files (MATLAB Report Generator)
- Subclass Reporter Definitions (MATLAB Report Generator)
- Define New Reporters (MATLAB Report Generator)