Main Content

Customize Test Results Reports

You can choose how to format and aggregate test results by customizing reports. 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.

Inherit the Report Class

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.

% class definition
classdef CustomReport < sltest.testmanager.TestResultReport
    % Report customization code here

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.

Method hierarchy for report layout

The result set block contains the result set table, the coverage table, and links to the table of contents.

Method hierarchy for result set

The test suite result block contains the test suite results table, the coverage table, requirements links, and links to the table of contents.

Method hierarchy for test suite result

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.

Method hierarchy for test case result

Modify the Class

To insert your own report content or change the layout of the generated report, modify the inherited class methods. For general information about modifying methods, see Modify Inherited Methods.

A simple modification to the generated report could be to add some text to the title page. The method used here is addTitlePage.

% class definition
classdef CustomReport < sltest.testmanager.TestResultReport
        function this = CustomReport(resultObjects, reportFilePath)
        function addTitlePage(obj)
            import mlreportgen.dom.*;
            % Add a custom message
            label = Text('Some custom content can be added here');
            % Call the superclass method to get the default behavior

A more complex modification of the generated report is to include a snapshot of the model that was tested.

% class definition
classdef CustomReport < sltest.testmanager.TestResultReport
        function this = CustomReport(resultObjects,reportFilePath)
        % Method to customize test case/iteration result section in the report
        function docPart = genTestCaseResultBlock(obj,result)
            % result: A structure containing test case or iteration result
            import mlreportgen.dom.*;
            % Call the superclass method to get the default behavior
            docPart = genTestCaseResultBlock@sltest.testmanager.TestResultReport(...
            % Get the test case result data for putting in the report
            tcrObj = result.Data;
            % Insert model screenshot at the test case result level
            if isa(tcrObj, 'sltest.testmanager.TestCaseResult')
                % Initialize model name
                modelName = '';
                % Check in the test case result if it has model information. If
                % not, it means there were iterations in the test case or a
                % model was not used.
                testSimMetaData = tcrObj.SimulationMetaData;
                if (~isempty(testSimMetaData))
                    modelName = testSimMetaData.modelName;
                % Get iteration results
                iterResults = getIterationResults(tcrObj);
                % Get the model name in case test case had iterations
                if (~isempty(iterResults))
                    modelName = iterResults(1).SimulationMetaData.modelName;
                % Insert model snapshot. This will not work for harnesses. With
                % minimal changes we can also open the harness used for
                % testing.
                if (~isempty(modelName))
                        outputFileName = [tempdir, modelName, '.png'];
                        if exist(outputFileName,'file')
                        print(outputFileName, '-s', '-dpng');
                        para = sltest.testmanager.ReportUtility.genImageParagraph(...

Generate a Report Using the Custom Class

After you customize the class and methods, use the to generate the report. You must use the 'CustomReportClass' name-value pair for the custom class, specified as a string. For example:

% Generate the result set from imported data
result = sltest.testmanager.importResults('demoResults.mldatx');

% Specify the report filename and path
filePath = '';

% Generate the report using the custom class,filePath, ...
            'LaunchReport', true);

Alternatively, you can create your custom report using the Test Manager report dialog box. Select a test result, click the Report button on the toolstrip, and specify the custom report class in the Create Test Result Report dialog box. For the Test Manager to use the custom report class, the class must be on the MATLAB path.

See Also


Related Topics