Main Content

sortByFixtures

クラス: matlab.unittest.TestSuite
名前空間: matlab.unittest

共有フィクスチャに基づくテスト スイートの並べ替え

構文

sortedSuite = sortByFixtures(suite)
[sortedSuite,I] = sortByFixtures(suite)

説明

sortedSuite = sortByFixtures(suite) はテスト スイートを並べ替えて、共有フィクスチャの設定および破棄操作を減らします。将来のリリースで変更される可能性があるため、sortedSuite での要素の順序には依存しないでください。

[sortedSuite,I] = sortByFixtures(suite) は、suite の要素の sortedSuite への配置を示す並べ替えインデックス I も返します。

入力引数

すべて展開する

一連のテスト。matlab.unittest.Test 配列として指定します。

出力引数

すべて展開する

順序付けされた一連のテスト。配列 matlab.unittest.Test として返されます。sortedSuite は、suite のテスト要素の順列です。

並べ替えインデックス。ベクトル、行列または多次元配列として返されます。Isuite と同じサイズで、suite の要素の orderedSuite への配置を示します。具体的には、sortedSuite = suite(I) です。

すべて展開する

現在の作業フォルダーで 3 つのテスト クラスを作成します。テスト クラス MyTestClassA および MyTestClassC は、同じ共有パス フィクスチャを使用します。

classdef (SharedTestFixtures={ ...
        matlab.unittest.fixtures.PathFixture('offPathFolder')}) ...
        MyTestClassA < matlab.unittest.TestCase
    methods (Test)
        function test_A(testCase)
            % test content
        end
    end
end
classdef MyTestClassB < matlab.unittest.TestCase
    methods (Test)
        function test_B(testCase)
            % test content
        end
    end
end
classdef (SharedTestFixtures={ ...
        matlab.unittest.fixtures.PathFixture('offPathFolder')}) ...
        MyTestClassC < matlab.unittest.TestCase
    methods (Test)
        function test_C(testCase)
            % test content
        end
    end
end

各クラスからテスト スイートを作成します。

import matlab.unittest.TestSuite;
suiteA = TestSuite.fromClass(?MyTestClassA);
suiteB = TestSuite.fromClass(?MyTestClassB);
suiteC = TestSuite.fromClass(?MyTestClassC);

スイートを連結し、テスト要素の順序を確認します。

suite = [suiteA suiteB suiteC];
{suite.Name}'
ans =

  3×1 cell array

    {'MyTestClassA/test_A'}
    {'MyTestClassB/test_B'}
    {'MyTestClassC/test_C'}

スイートを共有フィクスチャで並べ替えて、テスト要素の順序を確認します。

sortedSuite = sortByFixtures(suite);
{sortedSuite.Name}'
ans =

  3×1 cell array

    {'MyTestClassA/test_A'}
    {'MyTestClassC/test_C'}
    {'MyTestClassB/test_B'}

MyTestClassAMyTestClassC のテストは同じ共有テスト フィクスチャをもっているため、テスト要素はスイート内で隣接するように並べ替えられます。

ヒント

matlab.unittest.TestSuite のメソッドを複数回呼び出すのではなく、関数 testsuite を 1 回呼び出してテスト スイートを作成する場合、そのスイートは共有フィクスチャに基づいて自動的に保存されます。ただし、最初にスイートを作成した後で要素を追加、削除、または並べ替えた場合、sortByFixtures メソッドを呼び出してスイートを並べ替えてください。

バージョン履歴

R2018b で導入