table
类: matlab.unittest.TestResult
命名空间: matlab.unittest
将 TimeResult
数组转换为表
输入参数
results
— 运行测试套件的结果
matlab.unittest.TestResult
数组
运行测试套件的结果,指定为 matlab.unittest.TestResult
数组。
示例
创建测试结果表格
基于一组测试结果创建一个表,并使用该表对结果进行排序,然后将其导出到 CSV 文件中。
在当前文件夹中,创建一个包含 ExampleTest
类的文件。
classdef ExampleTest < matlab.unittest.TestCase methods(Test) function testOne(testCase) testCase.verifySize([1 2 3; 4 5 6],[2 3]); end function testTwo(testCase) testCase.verifyClass(@sin,?function_handle); end function testThree(testCase) testCase.assertEqual(7*2,14) end end end
在命令提示符下,基于 ExampleTest
类创建一个测试套件并运行测试。
results = run(testsuite('ExampleTest'));
Running ExampleTest ... Done ExampleTest __________
基于 results
数组创建一个表。
rt = table(results)
rt = 3×6 table Name Passed Failed Incomplete Duration Details _________________________ ______ ______ __________ _________ ____________ {'ExampleTest/testOne' } true false false 0.0063632 {1×1 struct} {'ExampleTest/testTwo' } true false false 0.0073147 {1×1 struct} {'ExampleTest/testThree'} true false false 0.0027218 {1×1 struct}
使用该表显示测试结果的摘要。
summary(rt)
Variables: Name: 3×1 cell array of character vectors Passed: 3×1 logical Values: True 3 False 0 Failed: 3×1 logical Values: True 0 False 3 Incomplete: 3×1 logical Values: True 0 False 3 Duration: 3×1 double Values: Min 0.0027218 Median 0.0063632 Max 0.0073147 Details: 3×1 cell
通过按降序对表行进行排序来查找最长的测试持续时间。
sorted = sortrows(rt,'Duration','descend')
sorted = 3×6 table Name Passed Failed Incomplete Duration Details _________________________ ______ ______ __________ _________ ____________ {'ExampleTest/testTwo' } true false false 0.0073147 {1×1 struct} {'ExampleTest/testOne' } true false false 0.0063632 {1×1 struct} {'ExampleTest/testThree'} true false false 0.0027218 {1×1 struct}
将排序后的结果导出到一个 CSV 文件,并查看文件内容。
writetable(sorted,'myTestResults.csv') type 'myTestResults.csv'
Name,Passed,Failed,Incomplete,Duration,Details ExampleTest/testTwo,1,0,0,0.0073147, ExampleTest/testOne,1,0,0,0.0063632, ExampleTest/testThree,1,0,0,0.0027218,
扩展功能
基于线程的环境
使用 MATLAB® backgroundPool
在后台运行代码或使用 Parallel Computing Toolbox™ ThreadPool
加快代码运行速度。
版本历史记录
在 R2014b 中推出
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)