Main Content

matlab.unittest.selectors.HasSharedTestFixture クラス

名前空間: matlab.unittest.selectors

共有テスト フィクスチャに基づいて TestSuite 配列要素を選択

説明

matlab.unittest.selectors.HasSharedTestFixture クラスは、共有テスト フィクスチャに基づいてテスト スイートをフィルター処理するセレクターを提供します。

クラスベースのテストの場合、対応する TestCase クラスの SharedTestFixtures クラスレベル属性で指定されたすべてのフィクスチャが共有テスト フィクスチャになります。

クラスの属性

Sealed
true

クラス属性の詳細については、クラスの属性を参照してください。

作成

説明

selector = matlab.unittest.selectors.HasSharedTestFixture(expectedFixture) は、expectedFixture と互換性がある共有テスト フィクスチャを使用している TestSuite 配列要素を選択するセレクターを作成し、ExpectedFixture プロパティを設定します。2 つのフィクスチャのクラスが同じで、環境に対する変更も同じである場合、それらには互換性があります。

プロパティ

すべて展開する

共有テスト フィクスチャ。matlab.unittest.fixtures.Fixture オブジェクトとして返されます。このプロパティの値は、セレクターの作成時に指定します。

属性:

GetAccess
public
SetAccess
private

すべて折りたたむ

HasSharedTestFixture クラスを使用してテストを選択して、フィルター処理されたテスト スイートを作成します。テスト コードを簡略化するために、この例のテスト クラスでは、実装していないテスト用のプレースホルダーとして無条件テスト エラーを使用しています。

現在のフォルダーに myTests という名前のフォルダーを作成します。その後、myTests 内の Feature1Test.m という名前のファイルで Feature1Test クラスを作成します。このクラスのテストでは、指定された警告を抑制するフィクスチャを使用しています。

classdef (SharedTestFixtures={ ...
        matlab.unittest.fixtures.SuppressedWarningsFixture( ...
        "MATLAB:rmpath:DirNotFound")}) ...
        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

myTests フォルダー内の Feature2Test.m という名前のファイルで Feature2Test クラスを作成します。このクラスのテストでは、一時フォルダーを作成するフィクスチャと指定された警告を抑制するもう 1 つのフィクスチャを使用しています。

classdef (SharedTestFixtures={ ...
        matlab.unittest.fixtures.TemporaryFolderFixture( ...
        "WithSuffix","_TestData"), ...
        matlab.unittest.fixtures.SuppressedWarningsFixture( ...
        "MATLAB:rmpath:DirNotFound")}) ...
        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.HasSharedTestFixture
import matlab.unittest.fixtures.SuppressedWarningsFixture
import matlab.unittest.fixtures.TemporaryFolderFixture

この例で使用する共有テスト フィクスチャと互換性があるフィクスチャを作成します。

warnf = SuppressedWarningsFixture("MATLAB:rmpath:DirNotFound");
tempf = TemporaryFolderFixture("WithSuffix","_TestData");

myTests フォルダーからテスト スイートを作成します。その後、TestSuite 配列要素の名前を表示します。テスト スイートには 4 つのテストが含まれています。

suite = testsuite("myTests");
disp({suite.Name}')
    {'Feature1Test/defaultBehavior'}
    {'Feature1Test/otherBehavior'  }
    {'Feature2Test/defaultBehavior'}
    {'Feature2Test/otherBehavior'  }

フィクスチャ tempf と互換性があるフィクスチャを使用しているテストをすべて選択します。Feature2Testtempf と互換性がある共有テスト フィクスチャがあるため、このクラスのテストがフィルター処理されたテスト スイートに含まれます。

suite1 = suite.selectIf(HasSharedTestFixture(tempf));
disp({suite1.Name}')
    {'Feature2Test/defaultBehavior'}
    {'Feature2Test/otherBehavior'  }

warnf と互換性があり、tempf とは互換性がないフィクスチャを使用しているテストをすべて選択します。この条件を満たすのは Feature1Test クラスのテストだけです。

suite2 = suite.selectIf( ...
    ~HasSharedTestFixture(tempf) & HasSharedTestFixture(warnf));
disp({suite2.Name}')
    {'Feature1Test/defaultBehavior'}
    {'Feature1Test/otherBehavior'  }

標準の一時フォルダーを作成するフィクスチャを使用しているテストのみを含めて、フィルター処理されたテスト スイートを myTests から直接作成します。セレクターで使用しているフィクスチャはいずれの共有テスト フィクスチャとも互換性がないため、結果のテスト スイートは空になります。Feature2Test のテストで一時フォルダーを作成するフィクスチャを使用していますが、それらのフィクスチャには一時フォルダー名の接尾辞が含まれています。

suite3 = TestSuite.fromFolder("myTests", ...
    HasSharedTestFixture(TemporaryFolderFixture))
suite3 = 

  1×0 Test array with properties:

    Name
    ProcedureName
    TestClass
    BaseFolder
    Parameterization
    SharedTestFixtures
    Tags

Tests Include:
   0 Parameterizations, 0 Shared Test Fixture Classes, 0 Tags.

バージョン履歴

R2014a で導入