matlab.unittest.plugins.XMLPlugin - Plugin that writes test results to XML file - MATLAB (original) (raw)
Main Content
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.
Methods
Examples
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.
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"/>
Version History
Introduced in R2015b