matlab.unittest.selectors.HasBaseFolder クラス
名前空間: matlab.unittest.selectors
ベース フォルダーに基づいて TestSuite
配列要素を選択
説明
matlab.unittest.selectors.HasBaseFolder
クラスは、テストのベース フォルダーに基づいてテスト スイートをフィルター処理するセレクターを提供します。
テストのベース フォルダーは、テストを定義するファイルが格納されたフォルダーです。名前空間で定義したテストでは、ベース フォルダーは最上位の名前空間フォルダーの親です。
作成
説明
入力引数
folder
— ベース フォルダー名
string スカラー | 文字ベクトル | matlab.unittest.constraints.Constraint
オブジェクト
ベース フォルダーの名前。string スカラー、文字ベクトル、または matlab.unittest.constraints.Constraint
オブジェクトとして指定します。ベース フォルダーに基づくテストの選択で適用される条件は次のとおりです。
string スカラーまたは文字ベクトルを指定した場合、テストのベース フォルダーが指定された値と同じでなければなりません。指定する値は絶対パスでなければなりません。
制約を指定した場合、テストのベース フォルダーがその制約を満たさなければなりません。
この引数は Constraint
プロパティを設定します。
プロパティ
Constraint
— ベース フォルダーが満たさなければならない条件
matlab.unittest.constraints.Constraint
オブジェクト
フィルター処理されたテスト スイートにテストを含めるためにベース フォルダーが満たさなければならない条件。matlab.unittest.constraints.Constraint
オブジェクトとして返されます。
このプロパティは入力引数 folder
によって設定されます。
string スカラーまたは文字ベクトルを指定した場合、テスト フレームワークは、このプロパティを指定されたベース フォルダーを期待値とする
IsEqualTo
制約に設定します。制約を指定した場合、テスト フレームワークは、このプロパティをその制約に設定します。
属性:
GetAccess | public |
SetAccess | immutable |
例
ベース フォルダーに基づくテストの選択
HasBaseFolder
クラスを使用してテストを選択して、フィルター処理されたテスト スイートを作成します。テスト コードを簡略化するために、この例のテスト クラスでは、実装していないテスト用のプレースホルダーとして無条件テスト エラーを使用しています。
現在のフォルダーに myTests
という名前のフォルダーを作成します。その後、myTests
に feature1
と feature2
の 2 つのフォルダーを作成します。
feature1
フォルダー内の Feature1Test.m
という名前のファイルで Feature1Test
クラスを作成します。
classdef Feature1Test < matlab.unittest.TestCase methods (Test) function defaultBehavior(testCase) testCase.verifyFail("Add code to test default behavior.") end function otherBehavior(testCase) testCase.verifyFail("Add code to test nondefault behavior.") end end end
feature2
フォルダー内の Feature2Test.m
という名前のファイルで Feature2Test
クラスを作成します。
classdef Feature2Test < matlab.unittest.TestCase methods (Test) function defaultBehavior(testCase) testCase.verifyFail("Add code to test default behavior.") end function otherBehavior(testCase) testCase.verifyFail("Add code to test nondefault behavior.") end end end
この例で使用するクラスをインポートします。
import matlab.unittest.TestSuite import matlab.unittest.selectors.HasBaseFolder import matlab.unittest.constraints.ContainsSubstring
現在のフォルダーが myTests
の親フォルダーであることを確認します。myTests
フォルダーとそのサブフォルダーからテスト スイートを作成します。その後、TestSuite
配列要素の名前を表示します。テスト スイートには feature1
フォルダーと feature2
フォルダーで定義されたテストが含まれています。
suite = testsuite("myTests","IncludingSubfolders",true); disp({suite.Name}')
{'Feature1Test/defaultBehavior'} {'Feature1Test/otherBehavior' } {'Feature2Test/defaultBehavior'} {'Feature2Test/otherBehavior' }
feature1
フォルダーで定義されたテストをすべて選択します。
suite1 = suite.selectIf(HasBaseFolder( ... fullfile(pwd,"myTests","feature1"))); disp({suite1.Name}')
{'Feature1Test/defaultBehavior'} {'Feature1Test/otherBehavior' }
suite
のテストのうち feature1
の外部で定義されたものをすべて選択します。フィルター処理されたテスト スイートには、feature2
フォルダーで定義されたテストのみが含まれます。
suite2 = suite.selectIf(~HasBaseFolder( ... fullfile(pwd,"myTests","feature1"))); disp({suite2.Name}')
{'Feature2Test/defaultBehavior'} {'Feature2Test/otherBehavior' }
部分文字列 "2"
をベース フォルダーに含むテストのみを含めて、フィルター処理されたテスト スイートを myTests
とそのサブフォルダーから直接作成します。
suite3 = TestSuite.fromFolder("myTests", ... HasBaseFolder(ContainsSubstring("2")), ... "IncludingSubfolders",true); disp({suite3.Name}')
{'Feature2Test/defaultBehavior'} {'Feature2Test/otherBehavior' }
バージョン履歴
R2014a で導入
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)