matlab.unittest.plugins.TestReportPlugin.producingPDF
类: matlab.unittest.plugins.TestReportPlugin
命名空间: matlab.unittest.plugins
创建生成 PDF 测试报告的插件
语法
说明
plugin = matlab.unittest.plugins.TestReportPlugin.producingPDF 创建一个插件,该插件在临时文件夹中生成测试结果的 PDF 报告。此语法等效于 plugin = matlab.unittest.plugins.TestReportPlugin.producingPDF([tempname '.pdf'])。
plugin = matlab.unittest.plugins.TestReportPlugin.producingPDF(___, 支持上述语法中的任何输入参量组合,且可使用一个或多个名称-值参量指定选项。例如,Name,Value)plugin = matlab.unittest.plugins.TestReportPlugin.producingPDF("PageOrientation","landscape") 创建一个生成横向方向测试报告的插件。
输入参数
测试报告文件的名称,指定为以 .pdf 结尾的字符串标量或字符向量。该值可以是相对于当前文件夹的路径,也可以是绝对路径。
示例: "myTestReport.pdf"
示例: "C:\work\myTestReport.pdf"
名称-值参数
以 Name1=Value1,...,NameN=ValueN 的形式指定可选参量对组,其中 Name 是参量名称,Value 是对应的值。名称-值参量必须出现在其他参量之后,但参量对组的顺序无关紧要。
示例: plugin = matlab.unittest.plugins.TestReportPlugin.producingPDF(PageOrientation="landscape")
在 R2021a 之前,使用逗号分隔每个名称和值,并用引号将 Name 引起来。
示例: plugin= matlab.unittest.plugins.TestReportPlugin.producingPDF("PageOrientation","landscape")
报告方向,指定为 "portrait" 或 "landscape"。默认情况下,该插件会生成一个纵向方向的报告。
测试报告的标题,指定为字符串标量或字符向量。默认情况下,插件使用 "MATLAB® Test Report" 作为标题。
示例: Title="My Test Report"
是否包含命令行窗口的文本输出,指定为数值或逻辑值 0 (false) 或 1 (true)。默认情况下,该插件不会在测试报告中包含命令行窗口的文本输出。
是否包含通过事件的诊断,指定为数值或逻辑值 0 (false) 或 1 (true)。默认情况下,插件不在测试报告中包含通过事件的诊断。
要在测试报告中包含的已记录诊断的最大详细级别,指定为从 0 到 4 的整数标量、matlab.automation.Verbosity 枚举对象或枚举的文本表示。插件包括在指定级别及更低级别记录的诊断。
| 数值表示 | 枚举成员名称 | 详细程度描述 |
|---|---|---|
0 | None | 无信息 |
1 | Terse | 最少的信息 |
2 | Concise | 适中信息量 |
3 | Detailed | 部分补充信息 |
4 | Verbose | 大量补充信息 |
默认情况下,插件包含在 matlab.automation.Verbosity.Terse 级别(级别 1)记录的诊断信息。要排除所记录的诊断信息,请将 LoggingLevel 指定为 matlab.automation.Verbosity.None(级别 0)。
记录的诊断是您使用 log (TestCase) 和 log (Fixture) 方法为测试框架提供的诊断。
示例: "LoggingLevel","detailed"
示例
根据两个测试文件创建一个测试套件,运行该套件,并生成 PDF 格式的结果报告。
在您的工作文件夹中创建一个名为 ScriptBasedTest.m 的新文件,其中包含以下测试脚本。该脚本包括两个失败且未完成的测试。
%% 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'))
创建一个名为 ClassBasedTest.m 的文件,其中包含以下测试类。该类包含一个失败的测试,经过参数化后,测试产生九个失败的测试结果。
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
在命令提示符下,根据两个测试文件创建一个测试套件。
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..创建一个静默测试运行器,从而不在命令行窗口输出任何信息。创建一个将输出发送到文件 MyTestReport.pdf 的 TestReportPlugin。
runner = TestRunner.withNoPlugins;
pdfFile = 'MyTestReport.pdf';
plugin = TestReportPlugin.producingPDF(pdfFile);将该插接添加到 TestRunner 并运行套件。
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(pdfFile)
根据一个基于函数的测试创建一个测试套件,运行该套件,并生成结果报告。包含通过诊断信息和命令行窗口的文本输出。
在您的工作文件夹中创建一个名为 FunctionBasedTest.m 的新文件,其中包含以下基于函数的测试。测试文件包括两个失败的测试。
%% 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
在命令提示符下,根据 FunctionBasedTest.m 创建一个测试套件。使用默认插件创建一个将输出显示到命令行窗口中的测试运行器。
import matlab.unittest.TestRunner; import matlab.unittest.TestSuite; import matlab.unittest.plugins.TestReportPlugin; suite = testsuite('FunctionBasedTest'); runner = TestRunner.withTextOutput;
创建一个将输出发送到文件 MyTestReport2.pdf 的 TestReportPlugin。在报告中包含通过诊断信息和命令行窗口的文本输出。
pdfFile = 'MyTestReport2.pdf'; plugin = TestReportPlugin.producingPDF(pdfFile,... 'IncludingPassingDiagnostics',true,'IncludingCommandWindowText',true);
将该插接添加到 TestRunner 并运行套件。
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.pdf打开测试报告。
open(pdfFile)
提示
将根据系统区域设置和您计算机上安装的字体系列生成 PDF 测试报告。在使用非英语区域设置生成报告时,除非您的计算机安装了 Noto Sans CJK 字体系列,否则报告可能使用井号字符 (#) 代替中文、日语和韩语字符。
版本历史记录
在 R2016b 中推出要修改测试报告的标题,请指定 Title 名称-值参量。
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.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)