matlab.unittest.plugins.XMLPlugin 类
以 XML 格式写入测试结果的插件
说明
XMLPlugin
类创建以 XML 格式将测试结果写入文件的插件。
构造
使用 matlab.unittest.plugins.XMLPlugin.producingJUnitFormat
方法实例化 XMLPlugin
。
复制语义
句柄。要了解句柄类如何影响复制操作,请参阅复制对象。
示例
将结果输出到 JUnit 样式的 XML 文件
创建包含以下测试类的 ExampleTest.m
。
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
根据 ExampleTest
类创建测试套件。创建静默测试运行程序。
import matlab.unittest.TestRunner import matlab.unittest.TestSuite import matlab.unittest.plugins.XMLPlugin suite = TestSuite.fromClass(?ExampleTest); runner = TestRunner.withNoPlugins;
创建将测试结果写入 myTestResults.xml
文件的 XMLPlugin
。
xmlFile = 'myTestResults.xml';
p = XMLPlugin.producingJUnitFormat(xmlFile);
将该插件添加到测试运行程序并运行该套件。
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}
查看该插件创建的文件中的内容。
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>
提示
如果测试文件是基于脚本的或基于函数的测试,则
<testcase>
元素的classname
属性的值是测试文件名。
版本历史记录
在 R2015b 中推出
另请参阅
外部网站
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
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)