matlab.unittest.plugins.TestReportPlugin.producingHTML - Create plugin that generates HTML test report - MATLAB (original) (raw)
Class: matlab.unittest.plugins.TestReportPlugin
Namespace: matlab.unittest.plugins
Create plugin that generates HTML test report
Syntax
Description
plugin = matlab.unittest.plugins.TestReportPlugin.producingHTML
creates a plugin that generates a multifile HTML test report in a temporary folder. The plugin uses the default filename index.html
for the main file of the report within the temporary folder. If you rerun the test suite with this plugin, then MATLAB® overwrites the contents of the folder.
This syntax is equivalent to plugin = matlab.unittest.plugins.TestReportPlugin.producingHTML(tempname)
.
plugin = matlab.unittest.plugins.TestReportPlugin.producingHTML([fileOrFolder](#mw%5F5c0cb103-77db-48b5-897c-9d720c19512f))
saves the report to the specified location:
- If you specify a file, the plugin generates a single-file report and saves it as the specified file. In a single-file HTML test report, all the contents of the report, such as text and images, are included in a single HTML file. (since R2024a)
- If you specify a folder, the plugin generates a multifile report and saves it to the specified folder.
plugin = matlab.unittest.plugins.TestReportPlugin.producingHTML(___,[Name,Value](#namevaluepairarguments))
specifies options using one or more name-value arguments in addition to any of the input argument combinations in previous syntaxes. For example, plugin = matlab.unittest.plugins.TestReportPlugin.producingHTML("MainFile","main.html")
creates a plugin that generates a multifile test report whose main file ismain.html
instead of index.html
.
Input Arguments
Name of the test report file for a single-file report or the test report folder for a multifile report, specified as a string scalar or character vector. The value can be a path relative to the current folder or an absolute path.
Example: "myTestReport.html"
Example: "C:\work\myTestReport"
Name-Value Arguments
Specify optional pairs of arguments asName1=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.producingHTML(MainFile="main.html")
Before R2021a, use commas to separate each name and value, and enclose Name
in quotes.
Example: plugin = matlab.unittest.plugins.TestReportPlugin.producingHTML("MainFile","main.html")
Name of the main HTML file of a multifile test report, specified as a string scalar or character vector ending in .html
or.htm
. If you do not specifyMainFile
, the plugin names the main file of the multifile test report index.html
.
Example: MainFile="main.html"
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"
Whether 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.
Whether 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 thematlab.automation.Verbosity.Terse
level (level 1). To exclude logged diagnostics, specify LoggingLevel
asmatlab.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"
Examples
Create a test suite from two test files, run the suite, and generate a single-file HTML test report.
In a file named eyeTest.m
in your current folder, create a function-based test to test the eye
function.
function tests = eyeTest tests = functiontests(localfunctions); end
function doubleClassTest(testCase) actual = eye; verifyClass(testCase,actual,"double") end
function singleClassTest(testCase) actual = eye("single"); verifyClass(testCase,actual,"single") end
function uint16ClassTest(testCase) actual = eye("uint16"); verifyClass(testCase,actual,"uint16") end
function sizeTest(testCase) expected = [7 13]; actual = eye(expected); verifySize(testCase,actual,expected) end
function valueTest(testCase) actual = eye(42); verifyEqual(testCase,unique(diag(actual)),1) % Diagonal values must be 1 verifyEqual(testCase,unique(triu(actual,1)),0) % Upper triangular values must be 0 verifyEqual(testCase,unique(tril(actual,-1)),0) % Lower triangular values must be 0 end
In another file named ZerosTest.m
in your current folder, create a class-based test to test the zeros
function.
classdef ZerosTest < matlab.unittest.TestCase properties (TestParameter) type = {'single','double','uint16'}; size = struct("s2d",[3 3],"s3d",[2 5 4]); end
methods (Test)
function testClass(testCase,size,type)
testCase.verifyClass(zeros(size,type),type)
end
function testSize(testCase,size)
testCase.verifySize(zeros(size),size)
end
function testDefaultClass(testCase)
testCase.verifyClass(zeros,"double")
end
function testDefaultSize(testCase)
testCase.verifySize(zeros,[1 1])
end
function testDefaultValue(testCase)
testCase.verifyEqual(zeros,0)
end
end
end
Import the TestReportPlugin
class.
import matlab.unittest.plugins.TestReportPlugin
Create a test suite from the test files.
suite = testsuite(["eyeTest.m" "ZerosTest.m"]);
Create a test runner with no plugins. This code creates a silent runner that produces no output.
runner = testrunner("minimal");
Create a plugin that generates a single-file HTML test report with"myTestReport.html"
as the HTML filename.
plugin = TestReportPlugin.producingHTML("myTestReport.html");
Add the plugin to the test runner and run the tests. In this example, all the tests pass, and the plugin generates a single-file HTML test report in the current folder.
runner.addPlugin(plugin) results = runner.run(suite)
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.html
results =
1×16 TestResult array with properties:
Name
Passed
Failed
Incomplete
Duration
Details
Totals: 16 Passed, 0 Failed, 0 Incomplete. 0.15478 seconds testing time.
To open the generated test report, click the hyperlink to the HTML file or use the open
function.
open("myTestReport.html")
Version History
Introduced in R2017b
To generate a single-file HTML test report, specify the name of the test report file by using the fileOrFolder input argument.
To modify the title of your test report, specify the Title
name-value argument.