applyFixture
クラス: matlab.unittest.fixtures.Fixture
名前空間: matlab.unittest.fixtures
作業を他のフィクスチャに委ねるフィクスチャのセットアップ
説明
入力引数
fixture1
— プライマリ フィクスチャ
matlab.unittest.fixtures.Fixture
のインスタンス
プライマリ フィクスチャ。matlab.unittest.fixtures.Fixture
のインスタンスとして指定します。
fixture2
— プライマリ フィクスチャに適用するフィクスチャ
matlab.unittest.fixtures.Fixture
のインスタンス
プライマリ フィクスチャ設定用のフィクスチャ。matlab.unittest.fixtures.Fixture
のインスタンスとして指定します。プライマリ フィクスチャは作業をこのフィクスチャに委ねます。
例
警告を非表示にする作業のデリゲート
検索パスからフォルダーを削除し、削除しようとしたフォルダーが検索パスにない場合に発生する警告を非表示にするフィクスチャを作成します。このフィクスチャは、SuppressedWarningsFixture
フィクスチャを使用して、指定された警告を無効にします。RemoveFolderFromPathFixture
による破棄の一部として、テスト フレームワークは適切な時点で SuppressedWarningsFixture
も破棄し、警告の状態を前の値に復元します。
classdef RemoveFolderFromPathFixture < matlab.unittest.fixtures.Fixture properties (SetAccess = immutable) Folder (1,1) string end methods function fixture = RemoveFolderFromPathFixture(folder) fixture.Folder = folder; end function setup(fixture) import matlab.unittest.fixtures.SuppressedWarningsFixture % Delegate to SuppressedWarningsFixture to suppress display of warnings. fixture.applyFixture(SuppressedWarningsFixture('MATLAB:rmpath:DirNotFound')); % Remove the folder from the path. originalPath = path; fixture.addTeardown(@()path(originalPath)); rmpath(fixture.Folder); end end methods (Access = protected) function bool = isCompatible(fixture1,fixture2) bool = fixture1.Folder == fixture2.Folder; end end end
一時テキスト ファイルを作成する作業のデリゲート
一時テキスト ファイルを作成するフィクスチャを構築します。このフィクスチャは TemporaryFolderFixture
フィクスチャを使用して一時フォルダーを作成したうえで、そのフォルダー内にテキスト ファイルを作成します。TemporaryTextFileFixture
の破棄の一環として、フレームワークは適切な時点で TemporaryFolderFixture
も破棄し、これによってフォルダーとその内容が削除されます。
classdef TemporaryTextFileFixture < matlab.unittest.fixtures.Fixture properties (SetAccess = private) File end methods function setup(fixture) import matlab.unittest.fixtures.TemporaryFolderFixture % Delegate to TemporaryFolderFixture to create a temporary folder. tempFixture = fixture.applyFixture(TemporaryFolderFixture); fixture.File = fullfile(tempFixture.Folder,'file.txt'); fid = fopen(fixture.File,'wt'); fixture.fatalAssertNotEqual(fid,-1); status = fclose(fid); fixture.fatalAssertEqual(status,0); end end end
バージョン履歴
R2016a で導入
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)