Customize Test Specification Reports
To customize the formatting, section ordering, or to remove content from a test specification report, you must first create a copy of the test case or test suite template. You can then modify the template and apply it to your test specification report. You use test suite templates for both test suites and test files. To add new content, create a new reporter and then, specify new holes to hold that content.
Note
To customize a report, you must have a Simulink® Report Generator™ license.
Update PDF or HTML Reports
This example creates a new test case reporter template for a PDF report. Use this process to remove content or change the formatting or order of a test specification report. The process is the same to create templates for HTML output and test suite reporter templates.
Create a copy of the default
TestCaseReporter
PDF template in the current working folder. This folder must be writable.For PDF and HTML output,sltest.testmanager.TestCaseReporter.createTemplate(... 'myCustomTCTemplate','pdf');
createTemplate
creates a zipped file that contains the template files and other supporting files. For PDF output, the file extension is.pdftx
and for HTML, it is.htmtx
.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. Both 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. Content holes are filled with the associated data when the report is generated. In this template file, you can reorder the report sections and delete template holes. This image shows a portion of the defaultdocpart_templates.html
file.For information on adding new content holes, see Add Content to Reports.
In the
stylesheets
folder, open and edit theroot.css
file using a text editor. This file controls the formatting of the report sections. You can change the table borders, font size, text color, and other styles. For example, to change the font size to 14 pixels, usefont-size: 14px;
. The font-size setting is shown in the second section of the file image. This image shows a portion of the defaultroot.css
file.To learn more about modifying report styles, see Modify Styles in PDF Templates (MATLAB Report Generator). For information on HTML styles, see Modify Styles in HTML Templates (MATLAB Report Generator).
Zip the files from the folder you used in Step 1 into 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.Use the
sltest.testmanager.TestSpecReport
function and specify themyCustomTCTemplate.pdftx
filename as an input argument.For example, use this code to create a test specification report that uses your custom template for the
AutopilotTestFile.mldatx
test file,openExample('GenerateATestSpecificationReportExample') testfile = 'AutopilotTestFile.mldatx'; sltest.testmanager.load(testfile); tfile = sltest.testmanager.TestFile(testfile); tsuites = getTestSuites(tfile); tcases = getTestCases(tsuites); sltest.testmanager.TestSpecReport(tcases,'testReport.pdf',... 'Author','John Smith','Title','Autopilot Test Spec Report',... 'LaunchReport',true,... 'TestCaseReporterTemplate','MyCustomTCTemplate.pdftx') sltest.testmanager.clear; sltest.testmanager.clearResults;
Update Word Reports
This example creates a new test case reporter template for a Microsoft® Word report. Use this process to remove content or change the formatting or order of a test specification report content. Use the same process to create a test suite reporter template.
Create a copy of the default
TestCaseReporter
Word template in the current working folder. The new file has a DOTX file extension. This example creates amyCustomTCTemplate.dotx
test case reporter template file in the current working directory.To create asltest.testmanager.TestCaseReporter.createTemplate(... 'myCustomTCTemplate','docx');
TestSuiteReporter
usesltest.testmanager.TestSuiteReporter.createTemplate
instead.In the current working folder outside of MATLAB, right-click the
myCustomTCTemplate.dotx
file and click Open. The file appears to be blank but has defined holes that are not visible until you open the Quick Parts.Note
If you double-click on the file name to open the file, it opens a Word document file and not the template file.
In the Insert tab, in the Text section, click Quick Parts.
In the Quick Parts library, click the Test Case Reporter section to populate the report with the default holes for the report.
Delete or move holes as desired. To change the formatting of the hole, see Specify Default Styles for Text That Fill Holes (MATLAB Report Generator).
Select all content in the template and reopen the Quick Parts library as described in step 3.
At the bottom of the panel, click Save Selection to Quick Part Gallery. The Create New Building Block dialog box opens.
Enter this required information:
Name — Name of the Quick Part library block. For this example, enter
TestCaseReporter
.Gallery — Type of the selected content. Select
Quick Parts
.Category — Category of the content. Select
mlreportgen
.Save in — Name of the template file. For this example, select
myCustomTCTemplate.dotx
.Options — How to insert the content. Select
Insert Content only
.
Click OK and then click Yes to confirm your changes.
Save the file as a DOTX file. You can then use the file as the template for your test case specification report.
For information on Word styles, see Modify Styles in Microsoft Word Templates (MATLAB Report Generator).
Add Content to Reports
To add new content to a Word, PDF, or HTML test specification 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 how to create a new test case reporter for a test specification report. 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. Outside of MATLAB® 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, zip the files usingzipTemplate
(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 use the correspondingget
method for that property in the customized class definition file. Then add the hole to the output type templates. For example, for a new section named References, thismyTCReporter.m
class definition file shows an addedReferences
property and a definedgetReferences
method.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, the code adds the test case reporter object to the report and usesrptview
(MATLAB Report Generator) to display the report. The code saves the report in themyCustomTestSpecRpt.pdf
file.myrpt = slreportgen.report.Report('myCustomTestSpecRpt.pdf'); testcaseRptr = myTCReporter('Object',test_cases); add(myrpt,testcaseRptr); close(myrpt); rptview(myrpt);
Related Topics
- Templates (MATLAB Report Generator)
- Open Template Files (MATLAB Report Generator)
- Subclass Reporter Definitions (MATLAB Report Generator)
- Define New Reporters (MATLAB Report Generator)
- Customize Test Results Reports