Main Content

このページの翻訳は最新ではありません。ここをクリックして、英語の最新版を参照してください。

matlab.unittest.fixtures.TemporaryFolderFixture クラス

パッケージ: matlab.unittest.fixtures

一時フォルダーを作成するフィクスチャ

説明

matlab.unittest.fixtures.TemporaryFolderFixture により、一時フォルダーを作成するフィクスチャが提供されます。テスト フレームワークがフィクスチャをセットアップすると、フィクスチャが一時フォルダーを作成します。テスト フレームワークがフィクスチャを破棄すると、フィクスチャがフォルダーとその内容をすべて削除します。フォルダーを削除する前に、フィクスチャは、一時フォルダーに定義されている MATLAB ファイル、P ファイルおよび MEX ファイルの定義をメモリからクリアします。

TemporaryFolderFixture および WorkingFolderFixture の両方のフィクスチャは一時フォルダーを作成します。WorkingFolderFixture とは異なり、TemporaryFolderFixture はフォルダーを現在の作業フォルダーとして設定しません。

構築

matlab.unittest.fixtures.TemporaryFolderFixture は一時フォルダーを作成するフィクスチャを構築します。

matlab.unittest.fixtures.TemporaryFolderFixture(Name,Value) は、1 つ以上の Name,Value の引数のペアで指定された追加オプションを使用して、一時フォルダーを作成するフィクスチャを構築します。

入力引数

すべて展開する

名前と値の引数

引数のオプションのペアを Name1=Value1,...,NameN=ValueN として指定します。ここで Name は引数名で、Value は対応する値です。名前と値の引数は他の引数の後になければなりませんが、ペアの順序は重要ではありません。

R2021a より前では、コンマを使用してそれぞれの名前と値を区切り、Name を引用符で囲みます。

テスト エラー発生時の一時フォルダーおよびその内容の保存実行のインジケーター。false または true (logical 0 または 1) で指定します。このプロパティは既定で false です。フィクスチャの構築時にこれを true として指定できます。

データ型: logical

一時フォルダー名の接尾辞。文字ベクトルとして指定します。

プロパティ

Folder

フィクスチャによって作成されるフォルダーの絶対パス。文字ベクトルとして指定します。

PreserveOnFailure

テスト エラー発生時の一時フォルダーおよびその内容の保存実行のインジケーター。このプロパティは logical(0) または logical(1) です。これは既定で logical(0) ですが、フィクスチャの構築時に 'PreservingOnFailure' 入力値が true に設定された場合は logical(1) に設定されます。

Suffix

一時フォルダーに使用する接尾辞。Name,Value のペアの引数 'WithSuffix' に文字ベクトルとして指定します。

コピーのセマンティクス

ハンドル。コピー操作に対するハンドル クラスの影響については、オブジェクトのコピーを参照してください。

すべて折りたたむ

次の tempFolderFixtureTest クラス定義を MATLAB® パス上に作成します。

classdef tempFolderFixtureTest < matlab.unittest.TestCase
    methods(Test)
        function test1(testCase)
            import matlab.unittest.fixtures.TemporaryFolderFixture
            
            tempFixture = testCase.applyFixture(TemporaryFolderFixture);
            
            disp(['The temporary folder: ' tempFixture.Folder])
        end
    end
end

コマンド プロンプトで、テストを実行します。

run(tempFolderFixtureTest);
Running tempFolderFixtureTest
The temporary folder: C:\Temp\tpfb1ae2cf_c9de_4de3_9557_00d52bfcc1b2
.
Done tempFolderFixtureTest
__________

一時フォルダーの名前はさまざまです。

次の anotherTempFolderFixtureTest クラス定義を MATLAB パス上に作成します。この例の目的として、関数 test1 には、テスト エラーを発生させるアサーションが含まれています。

classdef anotherTempFolderFixtureTest < matlab.unittest.TestCase
    methods(Test)
        function test1(testCase)
            import matlab.unittest.fixtures.TemporaryFolderFixture
            
            testCase.applyFixture(TemporaryFolderFixture( ...
                'PreservingOnFailure',true,'WithSuffix','TestData'));
            
            % Failed assertion, preserved temporary folder
            testCase.assertEqual(1,2)
        end
    end
end

コマンド プロンプトで、テストを実行します。

run(anotherTempFolderFixtureTest);
Running anotherTempFolderFixtureTest

================================================================================
Assertion failed in anotherTempFolderFixtureTest/test1 and it did not run to completion.

    ---------------------
    Framework Diagnostic:
    ---------------------
    assertEqual failed.
    --> The values are not equal using "isequaln".
    --> Failure table:
                Actual    Expected    Error    RelativeError
                ______    ________    _____    _____________
            
                1         2           -1       -0.5         
    
    Actual double:
             1
    Expected double:
             2

    ------------------
    Stack Information:
    ------------------
    In C:\Documents\anotherTempFolderFixtureTest.m (anotherTempFolderFixtureTest.test1) at 10
================================================================================
   [Terse] Diagnostic logged (2014-04-01T13:50:51): 
Because of a failure in the test using the TemporaryFolderFixture, the following folder will not be deleted:
C:\Temp\tp9f5aa9f1_ead1_4462_91f2_08bbe7d0316cTestData


.
Done anotherTempFolderFixtureTest
__________

Failure Summary:

     Name                                Failed  Incomplete  Reason(s)
    ==============================================================================
     anotherTempFolderFixtureTest/test1    X         X       Failed by assertion.

テストに失敗し、一時フォルダーが存続しています。C:\Temp\tp9f5aa9f1_ead1_4462_91f2_08bbe7d0316cTestData に示される一時フォルダーを開き、内容を調べることができます。

バージョン履歴

R2013b で導入