Main Content

matlab.unittest.fixtures.SuppressedWarningsFixture クラス

名前空間: matlab.unittest.fixtures
スーパークラス: matlab.unittest.fixtures.Fixture

警告の表示を抑制するフィクスチャ

説明

matlab.unittest.fixtures.SuppressedWarningsFixture クラスにより、警告の表示を抑制するフィクスチャが提供されます。テスト フレームワークでフィクスチャをセットアップすると、フィクスチャによって指定した警告が抑制されます。フレームワークでフィクスチャを破棄すると、フィクスチャによって警告の状態が元の値に戻されます。

matlab.unittest.fixtures.SuppressedWarningsFixture クラスは handle クラスです。

作成

説明

fixture = matlab.unittest.fixtures.SuppressedWarningsFixture(warnings) は、指定された警告の表示を抑制するフィクスチャを作成し、Warnings プロパティを設定します。

プロパティ

すべて展開する

抑制する警告の識別子。文字ベクトルの cell 配列として返されます。このプロパティの値は、フィクスチャの作成時に string 配列、文字ベクトル、または文字ベクトルの cell 配列として指定します。

例: {'MATLAB:MKDIR:DirectoryExists'}

例: {'MyComponent:FirstID','MyComponent:SecondID'}

属性:

GetAccess
public
SetAccess
private

すべて折りたたむ

SuppressedWarningsFixture インスタンスをテスト ケースで使用して、テストの実行時に警告を抑制できます。たとえば、存在しないフォルダーを検索パスから削除しようとしたときに発行される警告を抑制します。

rmpath コマンドを使用して存在しないフォルダーをパスから削除しようとすると、警告が発行されます。

rmpath nonexistentFolder
Warning: "nonexistentFolder" not found in path.

rmpath コマンドによって発行された警告の識別子を返します。

[~,identifier] = lastwarn
identifier =

    'MATLAB:rmpath:DirNotFound'

現在のフォルダー内の SuppressedWarningTest.m という名前のファイルで、rmpath の呼び出しが警告なしで実行されることを検証するテスト クラスを作成します。テストにパスするように、テストで applyFixture メソッドを呼び出します。

classdef SuppressedWarningTest < matlab.unittest.TestCase
    methods (Test)
        function testWarningFree(testCase)
            import matlab.unittest.fixtures.SuppressedWarningsFixture
            testCase.applyFixture( ...
                SuppressedWarningsFixture("MATLAB:rmpath:DirNotFound"))
            testCase.verifyWarningFree(@() rmpath("nonexistentFolder"))
        end
    end
end

テスト クラスを実行します。Test メソッドで関数ハンドルが呼び出されると、指定した警告がフィクスチャによって抑制されます。テストはパスします。

runtests("SuppressedWarningTest");
Running SuppressedWarningTest
.
Done SuppressedWarningTest
__________

テストの実行が完了すると、テスト フレームワークでフィクスチャが破棄され、環境が元の状態に戻ります。そのため、存在しないフォルダーで rmpath を新たに呼び出すと警告が発行されます。

rmpath nonexistentFolder
Warning: "nonexistentFolder" not found in path.

バージョン履歴

R2013b で導入