matlab.unittest.plugins.XMLPlugin 类
命名空间: matlab.unittest.plugins
超类: matlab.unittest.plugins.TestRunnerPlugin
将测试结果写入 XML 文件的插件
描述
matlab.unittest.plugins.XMLPlugin
类提供将测试结果写入 XML 文件的插件。
matlab.unittest.plugins.XMLPlugin
类是一个 handle
类。
创建对象
要创建 XMLPlugin
实例,请使用 producingJUnitFormat
静态方法。
方法
公共方法
matlab.unittest.plugins.XMLPlugin.producingJUnitFormat | 创建以 JUnit 样式 XML 格式生成测试结果的插件 |
示例
将测试结果写入 XML 文件
使用 XMLPlugin
类以 JUnit 样式 XML 格式生成测试结果。
在当前文件夹中,创建一个名为 sampleTest.m
的基于函数的测试文件。该文件包含两个能够通过的测试和一个失败的测试。
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
导入 XMLPlugin
类。
import matlab.unittest.plugins.XMLPlugin
用插件创建一个测试运行器,该插件以 JUnit 样式 XML 格式生成测试结果。要创建插件,请使用 producingJUnitFormat
静态方法。
runner = testrunner("minimal"); filename = "results.xml"; plugin = XMLPlugin.producingJUnitFormat(filename); addPlugin(runner,plugin)
从测试文件创建一个测试套件并运行测试。测试运行器运行测试,插件将测试结果保存到当前文件夹中名为 results.xml
的文件中。
suite = testsuite("sampleTest.m");
run(runner,suite);
查看生成的测试工件的内容。文件中的结果表明 testA
和 testC
通过,但 testB
由于验证失败而未通过。
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>
版本历史记录
在 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)