Main Content

matlab.unittest.parameters.Parameter クラス

名前空間: matlab.unittest.parameters

パラメーターの基底クラス

説明

パラメーター化されたテストで、パラメーターを使用してデータをテスト メソッドに渡します。

構築

静的な fromData メソッドを使用して、Parameter をインスタンス化します。

プロパティ

すべて展開する

この プロパティ は読み取り専用です。

Parameter を定義するプロパティの名前。文字ベクトルとして格納されます。

この プロパティ は読み取り専用です。

パラメーター値の名前。文字ベクトルとして格納されます。Name はパラメーターの特定の値を一意に識別します。

この プロパティ は読み取り専用です。

パラメーター値。任意の配列タイプとして格納されます。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

テストで singledoubleuint16 ではなく 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 パラメーターを再定義します。newTypenewSize からパラメーターを作成します。

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 で導入