applyFixture
클래스: matlab.unittest.fixtures.Fixture
패키지: matlab.unittest.fixtures
다른 픽스처(Fixture)로 작업을 위임하도록 픽스처 설정
설명
입력 인수
fixture1
— 주 픽스처(Primary Fixture)
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 명령 창에 입력하십시오. 웹 브라우저는 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)