matlab.unittest.parameters.Parameter クラス
名前空間: matlab.unittest.parameters
パラメーターの基底クラス
説明
パラメーター化されたテストで、パラメーターを使用してデータをテスト メソッドに渡します。
構築
静的な fromData
メソッドを使用して、Parameter
をインスタンス化します。
プロパティ
Property
— Parameter
を定義するプロパティの名前
文字ベクトル
この プロパティ は読み取り専用です。
Parameter
を定義するプロパティの名前。文字ベクトルとして格納されます。
Name
— パラメーター値の名前
文字ベクトル
この プロパティ は読み取り専用です。
パラメーター値の名前。文字ベクトルとして格納されます。Name
はパラメーターの特定の値を一意に識別します。
Value
— パラメーター値
任意の配列タイプ
この プロパティ は読み取り専用です。
パラメーター値。任意の配列タイプとして格納されます。Value
には、パラメーター化されたメソッドに TestRunner
が渡すデータが格納されます。
メソッド
fromData | データからパラメーターを作成 |
コピーのセマンティクス
値。値クラスがコピー操作に与える影響については、オブジェクトのコピーを参照してください。
例
テスト クラスの外部のパラメーターを使用するテスト
作業フォルダーで testZeros.m
を作成します。このクラスには 5 つのテスト メソッドがあり、パラメーター化されたテストが 11 個生成されます。
classdef testZeros < matlab.unittest.TestCase properties (TestParameter) type = {'single','double','uint16'}; outSize = struct('s2d',[3 3], 's3d',[2 5 4]); end methods (Test) function testClass(testCase, type, outSize) testCase.verifyClass(zeros(outSize,type), type); end function testSize(testCase, outSize) testCase.verifySize(zeros(outSize), outSize); end function testDefaultClass(testCase) testCase.verifyClass(zeros, 'double'); end function testDefaultSize(testCase) testCase.verifySize(zeros, [1 1]); end function testDefaultValue(testCase) testCase.verifyEqual(zeros,0); end end end
テストで single
、double
、uint16
ではなく uint64
および int64
データ型をパラメーター化に使用するよう、type
パラメーターを再定義します。パラメーターを作成します。
import matlab.unittest.parameters.Parameter newType = {'int64','uint64'}; param = Parameter.fromData('type',newType);
param
パラメーターを挿入するテスト スイートを作成します。スイート内のテストの名前を表示します。挿入されたパラメーターは #ext
で表されます。
import matlab.unittest.TestSuite suite = TestSuite.fromClass(?testZeros,'ExternalParameters',param); {suite.Name}'
ans = 9×1 cell array {'testZeros/testClass(type=int64#ext,outSize=s2d)' } {'testZeros/testClass(type=int64#ext,outSize=s3d)' } {'testZeros/testClass(type=uint64#ext,outSize=s2d)'} {'testZeros/testClass(type=uint64#ext,outSize=s3d)'} {'testZeros/testSize(outSize=s2d)' } {'testZeros/testSize(outSize=s3d)' } {'testZeros/testDefaultClass' } {'testZeros/testDefaultSize' } {'testZeros/testDefaultValue' }
スイートを実行します。
results = suite.run;
Running testZeros ......... Done testZeros __________
テストで 1 次元の配列と 4 次元の配列がパラメーター化されるよう、outSize
パラメーターを再定義します。newType
と newSize
からパラメーターを作成します。
newSize = struct('s2d',[5 3],'s4d',[2 3 2 4]); param = Parameter.fromData('type',newType,'outSize',newSize);
param
パラメーターを挿入するテスト スイートを作成します。スイート内のテストの名前を表示します。挿入されたパラメーターは #ext
で表されます。
import matlab.unittest.TestSuite suite = TestSuite.fromClass(?testZeros,'ExternalParameters',param); {suite.Name}'
ans = 9×1 cell array {'testZeros/testClass(type=int64#ext,outSize=s2d#ext)' } {'testZeros/testClass(type=int64#ext,outSize=s4d#ext)' } {'testZeros/testClass(type=uint64#ext,outSize=s2d#ext)'} {'testZeros/testClass(type=uint64#ext,outSize=s4d#ext)'} {'testZeros/testSize(outSize=s2d#ext)' } {'testZeros/testSize(outSize=s4d#ext)' } {'testZeros/testDefaultClass' } {'testZeros/testDefaultSize' } {'testZeros/testDefaultValue' }
スイートを実行します。
results = suite.run;
Running testZeros ......... Done testZeros __________
バージョン履歴
R2018b で導入
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)