Main Content

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.


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.

  1. Create a copy of the default TestCaseReporter PDF template in the current working folder. This folder must be writable.

    For PDF and HTML output, 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.

  2. To access the separate template files, unzip the PDF template file.

    Unzipping the file creates a docpart_templates.html file and a /stylesheets/root.css file in the new myCustomTCTemplate folder. Both PDF and HTML reports use HTML template files.

  3. 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 default docpart_templates.html file.

    For information on adding new content holes, see Add Content to Reports.

  4. In the stylesheets folder, open and edit the root.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, use font-size: 14px;. The font-size setting is shown in the second section of the file image. This image shows a portion of the default root.css file.

    root.css file contents

    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).

  5. Zip the files from the folder you used in Step 1 into the myCustomTCTemplate.pdftx file.


  6. 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. Add myCustomTCTemplate.pdftx to the Test Case Reporter field.

    • Use the sltest.testmanager.TestSpecReport function and specify the myCustomTCTemplate.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,

      testfile = 'AutopilotTestFile.mldatx';
      tfile = sltest.testmanager.TestFile(testfile);
      tsuites = getTestSuites(tfile);
      tcases = getTestCases(tsuites);
         'Author','John Smith','Title','Autopilot Test Spec Report',...

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.

  1. 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 a myCustomTCTemplate.dotx test case reporter template file in the current working directory.

    To create a TestSuiteReporter use sltest.testmanager.TestSuiteReporter.createTemplate instead.

  2. 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.


    If you double-click on the file name to open the file, it opens a Word document file and not the template file.

  3. In the Insert tab, in the Text section, click Quick Parts.

    Quick parts button

  4. In the Quick Parts library, click the Test Case Reporter section to populate the report with the default holes for the report.

    Test case reporter quick part

  5. 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).

  6. Select all content in the template and reopen the Quick Parts library as described in step 3.

  7. At the bottom of the panel, click Save Selection to Quick Part Gallery. The Create New Building Block dialog box opens.

  8. 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.

      Create new building block dialog box

  9. Click OK and then click Yes to confirm your changes.

  10. 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.

  1. To create a new test case reporter class, use the customizeReporter method of the TestCaseCreate reporter class. This command creates a new class folder in the current working folder. This new reporter inherits from the TestCaseReporter class.

    customTCRptr = ...
    See Subclass Reporter Definitions (MATLAB Report Generator).

    The @myTCReporter folder has a myTCReporter.m class definition file and a resources folder. The resources folder contains a templates folder, which contains folders and files for the report output types:

    • pdf folder

      • default.pdftx — Zipped PDF template file. Unzip this file using unzipTemplate (MATLAB Report Generator) and then open the template file using a text editor. After editing, use zipTemplate (MATLAB Report Generator).

    • docx folder

      • default.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 folder

      • default.htmt — Single-file HTML template. Open this file using a text editor.

      • default.htmtx — Zipped HTML template file. Unzip this file using unzipTemplate (MATLAB Report Generator) and then open the template file using a text editor. After editing, zip the files using zipTemplate (MATLAB Report Generator).

    For information on templates, see Templates (MATLAB Report Generator).

  2. In the @myTCReporter folder, open the class definition file myTCReporter.m in a text editor.

    Class definition file for custom reporter

  3. To add new content, add a property and use the corresponding get 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, this myTCReporter.m class definition file shows an added References property and a defined getReferences method.

    Updated class definition file

    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).

  4. 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 the TestCaseReporter, create a method called getTestDetails in the customized TestCaseReporter class definition file. You do not need to add a property or hole because they are already specified in the TestCaseReporter class from which the customized reporter inherits.

  5. 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 uses rptview (MATLAB Report Generator) to display the report. The code saves the report in the myCustomTestSpecRpt.pdf file.

    myrpt ='myCustomTestSpecRpt.pdf');
    testcaseRptr = myTCReporter('Object',test_cases);

Related Topics