Main Content

table

TimeResult 배열을 테이블로 변환

설명

예제

rt = table(results)results 배열에서 테이블 rt를 만듭니다. 행 정렬, 요약 표시 및 파일에 테이블 쓰기와 같은 table 기능에 액세스하려면 이 방법을 사용하십시오.

입력 인수

모두 확장

테스트 스위트 실행 결과로, 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에 개발됨