Main Content

run

クラス: matlab.unittest.TestRunner
名前空間: matlab.unittest

テスト スイートを実行

説明

results = run(runner,suite) は、指定されたテスト ランナーを使用して TestSuite 配列 suite を実行し、テスト実行の結果を返します。このメソッドは、テスト スイートの実行中に、テストに必要なセットアップ コードと破棄コードを自動的に実行します。

入力引数

すべて展開する

テスト ランナー。matlab.unittest.TestRunner オブジェクトとして指定します。

テスト スイート。matlab.unittest.TestSuite 配列として指定します。

出力引数

すべて展開する

テスト スイートの実行結果。matlab.unittest.TestResult 配列として返されます。results の要素は suite の要素に対応します。

すべて展開する

テキスト出力用に構成されたテスト ランナーでテスト スイートを実行します。

現在のフォルダーに関数ベースのテスト 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

sampleTest.m のテストからテスト スイートを作成します。

suite = testsuite("sampleTest.m");

テキスト出力を生成するテスト ランナーを作成し、それを使用してテストを実行します。テキスト出力には、テスト実行の進行状況とテスト失敗時の診断が含まれます。

runner = testrunner("textoutput");
results = run(runner,suite);
Running sampleTest
.
================================================================================
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
================================================================================
..
Done sampleTest
__________

Failure Summary:

     Name              Failed  Incomplete  Reason(s)
    ===============================================================
     sampleTest/testB    X                 Failed by verification.

失敗したテストの結果を表示します。

disp(results([results.Failed]))
  TestResult with properties:

          Name: 'sampleTest/testB'
        Passed: 0
        Failed: 1
    Incomplete: 0
      Duration: 1.2982
       Details: [1×1 struct]

Totals:
   0 Passed, 1 Failed (rerun), 0 Incomplete.
   1.2982 seconds testing time.

バージョン履歴

R2013a で導入