run
クラス: matlab.unittest.TestCase
パッケージ: matlab.unittest
テスト ケースに対応するテストを実行
説明
result = run(
は、testCase
)testCase
を定義するクラスのすべての Test
メソッドを実行し、テストの実行結果を matlab.unittest.TestResult
配列として返します。それぞれの TestResult
オブジェクトが Test
メソッドに対応します。
run
メソッドは、TestCase
サブクラスでの対話型の実験に便利なメソッドです。テキスト出力用に構成された TestRunner
インスタンスを使用してテストを実行します。テキスト出力には、テスト実行の進行状況とテスト失敗時の診断が含まれます。
入力引数
例
テスト クラスの作成と実行
テスト クラスを作成して実行し、Figure のプロパティをテストします。
現在のフォルダー内の FigurePropertiesTest.m
という名前のファイルで、次のようにして FigurePropertiesTest
テスト クラスを作成します。
matlab.unittest.TestCase
クラスをサブクラス化するテスト対象の Figure を表すプロパティを追加する
TestMethodSetup
のmethods
ブロックで各テストのセットアップ コードと破棄コードを追加するTest
のmethods
ブロックでテストを追加する
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.
次に、defaultCurrentPoint
の Test
メソッドを実行します。
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 で導入
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)