# table

TimeResult 数组转换为表

## 说明

rt = table(results) 基于 results 数组创建一个表 rt。使用此方法可访问 table 功能，如对行排序、显示摘要以及将表写入文件。

## 示例

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

results = run(testsuite('ExampleTest'));
Running ExampleTest
...
Done ExampleTest
__________

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}

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,