matlab.unittest.plugins.XMLPlugin class
Package: matlab.unittest.plugins
Plugin that writes test results in XML format
Description
The XMLPlugin
class creates a plugin that writes test results to a file
in XML format.
Construction
Instantiate an XMLPlugin
using the matlab.unittest.plugins.XMLPlugin.producingJUnitFormat
method.
Copy Semantics
Handle. To learn how handle classes affect copy operations, see Copying Objects.
Examples
Output Results to JUnit-style XML File
Create ExampleTest.m
containing the following
test class.
classdef ExampleTest < matlab.unittest.TestCase methods(Test) function testOne(testCase) % Test fails testCase.verifyEqual(5,4,'Testing 5==4') end function testTwo(testCase) % Test passes testCase.verifyEqual(5,5,'Testing 5==5') end function testThree(testCase) % Test is filtered testCase.assumeTrue(false) end end end
Create a test suite from
the ExampleTest
class. Create a silent test
runner.
import matlab.unittest.TestRunner import matlab.unittest.TestSuite import matlab.unittest.plugins.XMLPlugin suite = TestSuite.fromClass(?ExampleTest); runner = TestRunner.withNoPlugins;
Create an XMLPlugin
that writes test results to
the file myTestResults.xml
.
xmlFile = 'myTestResults.xml';
p = XMLPlugin.producingJUnitFormat(xmlFile);
Add the plugin to the test runner and run the suite.
runner.addPlugin(p) results = runner.run(suite); table(results)
ans = 3×6 table Name Passed Failed Incomplete Duration Details _________________________ ______ ______ __________ ________ ____________ {'ExampleTest/testOne' } false true false 0.26691 {1×1 struct} {'ExampleTest/testTwo' } true false false 0.010303 {1×1 struct} {'ExampleTest/testThree'} false false true 0.069284 {1×1 struct}
View the contents in the file created by the plugin.
disp(fileread(xmlFile))
<?xml version="1.0" encoding="utf-8"?> <testsuites> <testsuite errors="0" failures="1" name="ExampleTest" skipped="1" tests="3" time="0.3465"> <testcase classname="ExampleTest" name="testOne" time="0.26691"> <failure type="VerificationFailure">Verification failed in ExampleTest/testOne. ---------------- Test Diagnostic: ---------------- Testing 5==4 --------------------- Framework Diagnostic: --------------------- verifyEqual failed. --> The numeric values are not equal using "isequaln". --> Failure table: Actual Expected Error RelativeError ______ ________ _____ _____________ 5 4 1 0.25 Actual Value: 5 Expected Value: 4 ------------------ Stack Information: ------------------ In C:\work\ExampleTest.m (ExampleTest.testOne) at 4</failure> </testcase> <testcase classname="ExampleTest" name="testTwo" time="0.010303"/> <testcase classname="ExampleTest" name="testThree" time="0.069284"> <skipped>An assumption was not met in ExampleTest/testThree and it filtered the remainder of the test. --------------------- Framework Diagnostic: --------------------- assumeTrue failed. --> The value must evaluate to "true". Actual Value: logical 0 ------------------ Stack Information: ------------------ In C:\work\ExampleTest.m (ExampleTest.testThree) at 10</skipped> </testcase> </testsuite> </testsuites>
Tips
If your test file is a script-based or function-based test, the value of the
classname
attribute of the<testcase>
element is the test file name.
Version History
Introduced in R2015b
See Also
External Websites
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)