Main Content

run

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

テスト ケースに対応するテストを実行

説明

result = run(testCase) は、testCase を定義するクラスのすべての Test メソッドを実行し、テストの実行結果を matlab.unittest.TestResult 配列として返します。それぞれの TestResult オブジェクトが Test メソッドに対応します。

run メソッドは、TestCase サブクラスでの対話型の実験に便利なメソッドです。テキスト出力用に構成された TestRunner インスタンスを使用してテストを実行します。テキスト出力には、テスト実行の進行状況とテスト失敗時の診断が含まれます。

result = run(testCase,method) は、testCase の指定された Test メソッドを実行します。

入力引数

すべて展開する

テスト ケース。matlab.unittest.TestCase オブジェクトとして指定します。

実行する testCaseTest メソッドの識別子。string スカラー、文字ベクトル、または matlab.metadata.Method インスタンスとして指定します。

属性

Sealedtrue

メソッドの属性の詳細については、メソッドの属性を参照してください。

すべて展開する

テスト クラスを作成して実行し、Figure のプロパティをテストします。

現在のフォルダー内の FigurePropertiesTest.m という名前のファイルで、次のようにして FigurePropertiesTest テスト クラスを作成します。

  • matlab.unittest.TestCase クラスをサブクラス化する

  • テスト対象の Figure を表すプロパティを追加する

  • TestMethodSetupmethods ブロックで各テストのセットアップ コードと破棄コードを追加する

  • Testmethods ブロックでテストを追加する

classdef FigurePropertiesTest < matlab.unittest.TestCase
    properties
        TestFigure
    end

    methods (TestMethodSetup)
        function createFigure(testCase)
            testCase.TestFigure = figure;
            testCase.addTeardown(@close,testCase.TestFigure)
        end
    end

    methods (Test)
        function defaultCurrentPoint(testCase)
            cp = testCase.TestFigure.CurrentPoint;
            testCase.verifyEqual(cp,[0 0], ...
                "Default current point must be [0 0].")
        end

        function defaultCurrentObject(testCase)
            import matlab.unittest.constraints.IsEmpty
            co = testCase.TestFigure.CurrentObject;
            testCase.verifyThat(co,IsEmpty, ...
                "Default current object must be empty.")
        end
    end
end

テストを対話形式で実行するには、テスト クラスからテスト ケースを作成します。テスト ケースは、静的メソッド forInteractiveUse を使用して作成することもできます。

testCase = FigurePropertiesTest;

テスト ケースに対応するテストを実行します。両方のテストにパスします。

result1 = run(testCase)
Running FigurePropertiesTest
.
.
Done FigurePropertiesTest
__________
result1 = 
  1×2 TestResult array with properties:

    Name
    Passed
    Failed
    Incomplete
    Duration
    Details

Totals:
   2 Passed, 0 Failed, 0 Incomplete.
   0.10772 seconds testing time.

次に、defaultCurrentPointTest メソッドを実行します。

result2 = run(testCase,"defaultCurrentPoint")
Running FigurePropertiesTest
.
Done FigurePropertiesTest
__________
result2 = 
  TestResult with properties:

          Name: 'FigurePropertiesTest/defaultCurrentPoint'
        Passed: 1
        Failed: 0
    Incomplete: 0
      Duration: 0.0553
       Details: [1×1 struct]

Totals:
   1 Passed, 0 Failed, 0 Incomplete.
   0.055328 seconds testing time.

バージョン履歴

R2013a で導入