matlab.unittest.plugins.XMLPlugin Class
Namespace: matlab.unittest.plugins
Superclasses: matlab.unittest.plugins.TestRunnerPlugin
Plugin that writes test results to XML file
Description
The matlab.unittest.plugins.XMLPlugin
class provides a plugin that writes
test results to an XML file.
The matlab.unittest.plugins.XMLPlugin
class is a handle
class.
Creation
To create an XMLPlugin
instance, use the producingJUnitFormat
static method.
Methods
Public Methods
matlab.unittest.plugins.XMLPlugin.producingJUnitFormat | Create plugin that produces test results in JUnit-style XML format |
Examples
Write Test Results to XML File
Produce test results in JUnit-style XML format by using the XMLPlugin
class.
In your current folder, create a function-based test file named sampleTest.m
. 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
Import the XMLPlugin
class.
import matlab.unittest.plugins.XMLPlugin
Create a test runner with a plugin that produces test results in JUnit-style XML format. To create the plugin, use the producingJUnitFormat
static method.
runner = testrunner("minimal"); filename = "results.xml"; plugin = XMLPlugin.producingJUnitFormat(filename); addPlugin(runner,plugin)
Create a test suite from the test file and run the tests. The test runner runs the tests, and the plugin saves the test results to a file named results.xml
in your current folder.
suite = testsuite("sampleTest.m");
run(runner,suite);
View the contents of the generated test artifact. The results in the file indicate that testA
and testC
passed but testB
failed due to a verification failure.
disp(fileread(filename))
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> <testsuites> <testsuite errors="0" failures="1" name="sampleTest" skipped="0" tests="3" time="1.3417"> <testcase classname="sampleTest" name="testA" time="0.38058"/> <testcase classname="sampleTest" name="testB" time="0.92769"> <failure type="VerificationFailure">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</failure> </testcase> <testcase classname="sampleTest" name="testC" time="0.033431"/> </testsuite> </testsuites>
Version History
Introduced in R2015b
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)