matlab.unittest.plugins.TestReportPlugin.producingHTML
Class: matlab.unittest.plugins.TestReportPlugin
Package: matlab.unittest.plugins
Constructs plugin that produces .html
report
Syntax
Description
matlab.unittest.plugins.TestReportPlugin.producingHTML
constructs a plugin that produces a .html
report of test results
in a temporary folder. Within that folder, the main file of the report is
index.html
. If you rerun the test suite with this plugin,
then MATLAB® overwrites the contents in the folder.
This syntax is equivalent to
matlab.unittest.plugins.TestReportPlugin.producingHTML(tempname)
.
matlab.unittest.plugins.TestReportPlugin.producingHTML(
saves
the report to the htmlFolder
)htmlFolder
folder.
matlab.unittest.plugins.TestReportPlugin.producingHTML(___,
constructs a plugin with additional options specified by one or more
Name,Value
)Name,Value
pair arguments. You can use this syntax with any
of the arguments from the previous syntaxes.
Input Arguments
htmlFolder
— Output folder
character vector | string scalar
Output folder, specified as a character vector or string scalar.
htmlFolder
can be a relative or absolute path. By
default, within the folder, the main file of the report is
index.html
. To change the name of the main file, use
the 'MainFile'
name-value pair argument.
Example: 'TestRunOutput'
Example: 'C:\myWork\testResults'
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.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: TestReportPlugin.producingHTML('myTestOutput','MainFile','main.html')
creates a plugin that outputs results to the myTestOutput
folder,
with a main file named main.html
instead of
index.html
.
MainFile
— Main file name
character vector | string scalar
Main HTML
file name, specified as a character
vector or string scalar.
Example: 'main.html'
IncludingCommandWindowText
— Include Command Window text in report
false
(default) | true
Include Command Window text in report, specified as false
or
true
. By default, IncludingCommandWindowText
is false
and the text output from the Command Window is excluded from
the report. To include Command Window text in the report, specify
IncludingCommandWindowText
as true
.
Data Types: logical
IncludingPassingDiagnostics
— Include passing event diagnostics
false
(default) | true
Include passing event diagnostics, specified as false
or
true
. By default, IncludingPassingDiagnostics
is false
and the diagnostics from passing events are excluded from
the report. To include diagnostics from passing events in the report, specify
IncludingPassingDiagnostics
as true
.
Data Types: logical
LoggingLevel
— Maximum level of logged diagnostics
1 (default) | 0 | 2 | 3 | 4 | matlab.unittest.Verbosity
enumeration | enumeration name as string or char vector
Maximum level at which logged diagnostics are included by the plugin instance, specified as an integer value from 0 through 4, a matlab.unittest.Verbosity
enumeration object, or a string scalar or character vector corresponding to one of the predefined enumeration member names. The plugin includes diagnostics that are logged at this level and below. Integer values correspond to the members of the matlab.unittest.Verbosity
enumeration.
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.unittest.Verbosity.Terse
level (level 1). To exclude logged diagnostics, specify LoggingLevel
as Verbosity.None
(level 0).
Logged diagnostics are diagnostics that you supply to the
testing framework with a call to the log (TestCase)
or log
(Fixture)
method.
Examples
Generate Test Result Report in .html
Format
Create a test suite from two test files, run the suite, and
generate a .html
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 tests.
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 generates a
.html
test report in a folder named
myResults
.
runner = TestRunner.withNoPlugins;
htmlFolder = 'myResults';
plugin = TestReportPlugin.producingHTML(htmlFolder);
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\myResults\index.html result = 1×284 TestResult array with properties: Name Passed Failed Incomplete Duration Details Totals: 282 Passed, 2 Failed, 2 Incomplete. 1.6712 seconds testing time.
Open the test report by clicking the name of the saved file. In this
example the file name is
C:\work\myResults\index.html
.
Version History
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)