Main Content

generatePDFReport

Class: matlab.unittest.TestResult
Namespace: matlab.unittest

Generate PDF test report from test results

Since R2022a

Description

example

generatePDFReport(results) generates a test report from the test results in PDF format and saves it to a temporary folder.

Use this method to generate a PDF test report once the test run is complete and the test results are available.

generatePDFReport(results,filename) saves the report using the specified filename.

example

generatePDFReport(___,Name=Value) specifies options using one or more name-value arguments in addition to any of the input argument combinations in previous syntaxes. For example, generatePDFReport(results,PageOrientation="landscape") generates a test report in landscape orientation.

Input Arguments

expand all

Test results, specified as a matlab.unittest.TestResult array.

Name of the test report file, specified as a string scalar or character vector ending in .pdf. The value can be a path relative to the current folder or an absolute path.

Example: "myTestReport.pdf"

Example: "C:\work\myTestReport.pdf"

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: generatePDFReport(results,PageOrientation="landscape") generates a test report in landscape orientation.

Report orientation, specified as "portrait" or "landscape". By default, the method generates a report in portrait orientation.

Title of the test report, specified as a string scalar or character vector. By default, the method uses "MATLAB® Test Report" as the title.

Example: Title="My Test Report"

Examples

expand all

Run a suite of tests and then generate a PDF test report from the test results.

Create a function-based test sampleTest.m in your current folder. The file contains two tests that pass and one test that fails.

function tests = sampleTest
tests = functiontests(localfunctions);
end

function testA(testCase)      % Test passes
verifyEqual(testCase,2+3,5)
end

function testB(testCase)      % Test fails
verifyGreaterThan(testCase,13,42)
end

function testC(testCase)      % Test passes
verifySubstring(testCase,"Hello World!","llo")
end

Run the tests in sampleTest.m.

results = runtests("sampleTest");
Running sampleTest
.
================================================================================
Verification failed in sampleTest/testB.
    ---------------------
    Framework Diagnostic:
    ---------------------
    verifyGreaterThan failed.
    --> The value must be greater than the minimum value.
    
    Actual Value:
        13
    Minimum Value (Exclusive):
        42
    ------------------
    Stack Information:
    ------------------
    In C:\work\sampleTest.m (testB) at 10
================================================================================
..
Done sampleTest
__________

Failure Summary:

     Name              Failed  Incomplete  Reason(s)
    ===============================================================
     sampleTest/testB    X                 Failed by verification.

Generate a PDF test report from the test results in a temporary folder. By default, the report has portrait orientation.

generatePDFReport(results)
Generating test report. Please wait.
    Preparing content for the test report.
    Adding content to the test report.
    Writing test report to file.
Test report has been saved to:
 C:\TEMP\tp47385ca4_0f5e_4b7a_b30d_790768c79edd.pdf

Generate another report in landscape orientation, and save it as myTestReport.pdf in your current folder.

generatePDFReport(results,"myTestReport.pdf",PageOrientation="landscape")
Generating test report. Please wait.
    Preparing content for the test report.
    Adding content to the test report.
    Writing test report to file.
Test report has been saved to:
 C:\work\myTestReport.pdf

Open the test report in your current folder.

open("myTestReport.pdf")

Limitations

  • A test report generated by the generatePDFReport method does not include the text output from the Command Window.

Tips

  • When you generate a test report from test results that are created by a default runner, the report includes diagnostics for failing events and messages logged at the matlab.automation.Verbosity.Terse level. To generate a test report that includes diagnostics for passing events or messages logged at different verbosity levels, first customize your test run by adding a DiagnosticsRecordingPlugin instance to the runner. For example, run your tests and generate a test report that includes passing diagnostics and messages logged at all verbosity levels.

    import matlab.unittest.plugins.DiagnosticsRecordingPlugin
    import matlab.automation.Verbosity
    suite = testsuite("sampleTest");
    runner = testrunner("minimal");
    runner.addPlugin(DiagnosticsRecordingPlugin( ...
        IncludingPassingDiagnostics=true,LoggingLevel=Verbosity.Verbose))
    results = run(runner,suite);
    generatePDFReport(results)
  • To generate a test report without explicitly collecting the test results, customize your test run by adding a TestReportPlugin instance to the test runner.

  • PDF test reports are generated based on your system locale and the font families installed on your machine. When generating a report with a non-English locale, unless your machine has the Noto Sans CJK font families installed, the report might have pound sign characters (#) in place of Chinese, Japanese, and Korean characters.

Version History

Introduced in R2022a

expand all