matlab.unittest.plugins.TestReportPlugin.producingPDF
R2026bClass: matlab.unittest.plugins.TestReportPlugin
Namespace: matlab.unittest.plugins
Create plugin that generates PDF test report
Syntax
Description
plugin = matlab.unittest.plugins.TestReportPlugin.producingPDF
creates a plugin that generates a PDF report of test results in a temporary folder.
This syntax is equivalent to plugin =
matlab.unittest.plugins.TestReportPlugin.producingPDF([tempname
'.pdf']).
plugin = matlab.unittest.plugins.TestReportPlugin.producingPDF(___,
specifies options using one or more name-value arguments in addition to any of the
input argument combinations in previous syntaxes. For example, Name=Value)plugin =
matlab.unittest.plugins.TestReportPlugin.producingPDF(PageOrientation="landscape")
creates a plugin that generates a test report in landscape orientation.
Input Arguments
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: plugin =
matlab.unittest.plugins.TestReportPlugin.producingPDF(PageOrientation="landscape")
Report orientation, specified as "portrait" or "landscape". By default, the plugin generates a report in portrait orientation.
Title of the test report, specified as a string scalar or character vector. By default, the
plugin uses "MATLAB® Test Report" as the title.
Example: Title="My Test Report"
Option to include the text output from the Command Window, specified as a numeric or
logical 0 (false) or 1
(true). By default, the plugin does not include the text output
from the Command Window in the test report.
Option to include the diagnostics for passing events, specified as a numeric or
logical 0 (false) or 1
(true). By default, the plugin does not include the diagnostics
for passing events in the test report.
Maximum verbosity level of logged diagnostics to include in the test report, specified
as an integer scalar from 0 through 4, a matlab.automation.Verbosity enumeration object, or a text representation of
the enumeration. The plugin includes diagnostics logged at the specified level and
below.
| Numeric Representation | Enumeration Member Name | Verbosity Description |
|---|---|---|
0 | None | No information |
1 | Terse | Minimal information |
2 | Concise | Moderate amount of information |
3 | Detailed | Some supplemental information |
4 | Verbose | Lots of supplemental information |
By default, the plugin includes diagnostics logged at the
matlab.automation.Verbosity.Terse level (level 1). To exclude
logged diagnostics, specify LoggingLevel as
matlab.automation.Verbosity.None (level 0).
Logged diagnostics are diagnostics that you supply to
the testing framework with the log (TestCase) and log (Fixture) methods.
Example: LoggingLevel="detailed"
Option to include requirements information in the test report, specified as one of these values:
"auto"— If a test has linked requirements, the report includes information about the requirements verification status. If there are no linked requirements, the report does not contain requirements information."on"— If a test has linked requirements, the report includes information about the requirements verification status. If there are no linked requirements, the report includes an indication that there is no requirements information."off"— The report does not include requirements information.
To include requirements information, the tests must have verification links to requirements and you must have MATLAB Test™ and Requirements Toolbox™ licenses. For more information, see Include Requirements Verification Status in Test Reports (MATLAB Test).
Example:
IncludingRequirements="on"
Examples
Create a test suite from two test files, run the suite, and generate a PDF report of the results.
Create a new file in your working folder
named ScriptBasedTest.m containing the
following test script. The script includes two failing and incomplete
tests.
%% Test double class expSolution = 'double'; actSolution = ones; assert(isa(actSolution,expSolution)) %% Test single class expSolution = 'single'; actSolution = ones('single'); assert(isa(actSolution,expSolution)) %% Test uint16 class expSolution = 'uint16'; actSolution = ones('uint16'); assert(isa(actSolution,expSolution)) %% Test that fails assert(false==true); %% Another test that fails assert(strcmp('correlation','causation'))
Create a file named
ClassBasedTest.m containing the following test
class. The class includes a failing test that, with parameterization,
results in nine failed test results.
classdef ClassBasedTest < matlab.unittest.TestCase properties (ClassSetupParameter) generator = {'twister','combRecursive','multFibonacci'}; end properties (MethodSetupParameter) seed = {0,123,4294967295}; end properties (TestParameter) dim1 = struct('small',1,'medium',2,'large',3); dim2 = struct('small',2,'medium',3,'large',4); dim3 = struct('small',3,'medium',4,'large',5); type = {'single','double'}; end methods (TestClassSetup) function ClassSetup(testCase,generator) orig = rng; testCase.addTeardown(@rng,orig) rng(0, generator) end end methods (TestMethodSetup) function MethodSetup(testCase,seed) orig = rng; testCase.addTeardown(@rng,orig) rng(seed) end end methods (Test, ParameterCombination='sequential') function testSize(testCase,dim1,dim2,dim3) testCase.verifySize(rand(dim1,dim2,dim3),[dim1 dim2 dim3]) end end methods (Test, ParameterCombination='pairwise') function testRepeatable(testCase,dim1,dim2,dim3) state = rng; firstRun = rand(dim1,dim2,dim3); rng(state) secondRun = rand(dim1,dim2,dim3); testCase.verifyEqual(firstRun,secondRun); end end methods (Test) function testClass(testCase,dim1,dim2,type) testCase.verifyClass(rand(dim1,dim2,type),type) end end end
At the command prompt, create a test suite from both test files.
import matlab.unittest.TestRunner; import matlab.unittest.TestSuite; import matlab.unittest.plugins.TestReportPlugin; suite = testsuite({'ScriptBasedTest','ClassBasedTest'})
suite =
1×284 Test array with properties:
Name
ProcedureName
TestClass
BaseFolder
Parameterization
SharedTestFixtures
Tags
Tests Include:
17 Unique Parameterizations, 0 Shared Test Fixture Classes, 0 Tags..Create a silent test runner, so that there is no information output to
the command window. Create a TestReportPlugin that sends
output to the file MyTestReport.pdf.
runner = TestRunner.withNoPlugins;
pdfFile = 'MyTestReport.pdf';
plugin = TestReportPlugin.producingPDF(pdfFile);Add the plugin to the TestRunner and run the
suite.
runner.addPlugin(plugin); result = runner.run(suite)
Generating report. Please wait.
Preparing content for the report.
Adding content to the report.
Writing report to file.
Report has been saved to: C:\work\MyTestReport.pdf
result =
1×284 TestResult array with properties:
Name
Passed
Failed
Incomplete
Duration
Details
Totals:
282 Passed, 2 Failed, 2 Incomplete.
2.2054 seconds testing time.Open the test report.
open(pdfFile)
Create a test suite from a function-based test, run the suite, and generate a report of the results. Include passing diagnostics and the text output to the Command Window.
Create a new file in your working folder named FunctionBasedTest.m containing
the following function-based test. The test file includes two failing
tests.
%% Main function to generate tests function tests = FunctionBasedTest tests = functiontests(localfunctions); end %% Test Functions function passingTest(testCase) actSolution = 13*3+7*5; expSolution = 74; verifyEqual(testCase,actSolution,expSolution) end function failingTest(testCase) actSolution = single(1); verifyTrue(testCase,actSolution) end function anotherPassingTest(testCase) verifyClass(testCase,string('some text'),'string') end function anotherFailingTest(testCase) verifyTrue(testCase,strcmp('42','everything')) end
At the command prompt, create a test suite from FunctionBasedTest.m.
Create a test runner that displays output to the command window using
the default plugin.
import matlab.unittest.TestRunner import matlab.unittest.TestSuite import matlab.unittest.plugins.TestReportPlugin suite = testsuite('FunctionBasedTest'); runner = TestRunner.withTextOutput;
Create a TestReportPlugin that sends output
to the file MyTestReport2.pdf. Include passing
diagnostics and text output from the Command Window in the report.
pdfFile = 'MyTestReport2.pdf'; plugin = TestReportPlugin.producingPDF(pdfFile, ... IncludingPassingDiagnostics=true,IncludingCommandWindowText=true);
Add the plugin to the TestRunner and
run the suite.
runner.addPlugin(plugin); result = runner.run(suite);
Running FunctionBasedTest
.
================================================================================
Verification failed in FunctionBasedTest/failingTest.
---------------------
Framework Diagnostic:
---------------------
verifyTrue failed.
--> The value must be logical. It is of type "single".
Actual single:
1
------------------
Stack Information:
------------------
In C:\Work\FunctionBasedTest.m (failingTest) at 15
================================================================================
..
================================================================================
Verification failed in FunctionBasedTest/anotherFailingTest.
---------------------
Framework Diagnostic:
---------------------
verifyTrue failed.
--> The value must evaluate to "true".
Actual logical:
0
------------------
Stack Information:
------------------
In C:\Work\FunctionBasedTest.m (anotherFailingTest) at 23
================================================================================
.
Done FunctionBasedTest
__________
Failure Summary:
Name Failed Incomplete Reason(s)
===================================================================================
FunctionBasedTest/failingTest X Failed by verification.
-----------------------------------------------------------------------------------
FunctionBasedTest/anotherFailingTest X Failed by verification.
Generating report. Please wait.
Preparing content for the report.
Adding content to the report.
Writing report to file.
Report has been saved to: C:\Work\MyTestReport2.pdfOpen the test report.
open(pdfFile)
Tips
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 R2016bIf you have MATLAB
Test and Requirements Toolbox licenses, when you generate a test report, the report includes information about
linked requirements by default. You can specify whether to include requirements information by
using the new IncludingRequirements name-value argument.
In previous releases, test reports do not include requirements information. To preserve
this behavior, specify IncludingRequirements as
"off".
Test reports have an improved appearance. The improvements include a redesigned cover page and support for viewing the contents in light or dark theme. A PDF test report uses the theme of the application that renders it.
To modify the title of your test report, specify the Title name-value
argument.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)