Main Content

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.

  1. 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 is myCustomTCTemplate.

    sltest.testmanager.TestCaseReporter.createTemplate(...
       'myCustomTCTemplate','pdf');
    For pdf and zip (zip is used for HTML) output, createTemplate creates a zipped file. docx (Word) output it creates a .dotx template file.

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

    unzipTemplate('myCustomTCTemplate.pdftx');
    Unzipping the file creates a docpart_templates.html file and a /stylesheets/root.css file in the new myCustomTCTemplate folder. 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. In this file, you can reorder the report sections and delete template holes. A portion of the docpart_templates.html file is shown.

  4. 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 example, to set a font size to 14 pixels, use font-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 a Microsoft Word Template (MATLAB Report Generator) or Modify Styles in HTML Templates (MATLAB Report Generator), respectively.

  5. Zip the files into to the myCustomTCTemplate.pdftx file.

    zipTemplate('myCustomTCTemplate.pdftx');

  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.

    • Specify the myCustomTCTemplate.pdftx file name in the TestCaseReporterTemplate property of the sltest.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.

  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 = ...
      sltest.testmanager.TestCaseReporter.customizeReporter...
      ('@myTCReporter');
    See Subclass a Reporter Definition (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. Open this template file by right-clicking and selecting Open from the context menu. If you click the file name to open it, the Word file associated with the template opens instead of the template file. See Open a Template File (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, use 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.

  3. To add new content, add a property and define a get<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 a getReferences method in the myTCReporter.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 a Microsoft Word Template (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 Types of 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 use rptview (MATLAB Report Generator) to display it. The report is saved in the myCustomTestSpecRpt.pdf file.

    myrpt = slreportgen.report.Report('myCustomTestSpecRpt.pdf');
    testcaseRptr = myTCReporter('Object',test_cases);
    
    add(myrpt,testcaseRptr); 
    close(myrpt); 
    rptview(myrpt); 
    

Related Topics