table
Class: matlab.unittest.TestResult
Namespace: matlab.unittest
Convert TimeResult array to table
Syntax
Description
Input Arguments
Results of running a test suite, specified as a
matlab.unittest.TestResult array.
Examples
Create a table from a set of test results, and use the table to sort the results and export them to a CSV file.
In your current folder, create a file containing the ExampleTest
class.
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
At the command prompt, create a test suite from the ExampleTest
class and run the tests.
results = run(testsuite('ExampleTest'));
Running ExampleTest ... Done ExampleTest __________
Create a table from the results array.
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}
Use the table to display a summary of the test results.
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
Find the longest test duration by sorting the table rows in descending order.
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}
Export the sorted results to a CSV file and view the file contents.
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,
Extended Capabilities
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool.
Version History
Introduced in R2014b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Website auswählen
Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .
Sie können auch eine Website aus der folgenden Liste auswählen:
So erhalten Sie die bestmögliche Leistung auf der Website
Wählen Sie für die bestmögliche Website-Leistung die Website für China (auf Chinesisch oder Englisch). Andere landesspezifische Websites von MathWorks sind für Besuche von Ihrem Standort aus nicht optimiert.
Amerika
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- 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)