MATLAB 帮助中心
类: matlab.unittest.fixtures.Fixture 命名空间: matlab.unittest.fixtures
设置脚手架以将工作委派给另一个脚手架
applyFixture(fixture1,fixture2)
f = applyFixture(fixture1,fixture2)
applyFixture(fixture1,fixture2) 设置 fixture2 以与 fixture1 一起使用。要将工作委派给 fixture2,请从 fixture1 的 setup 方法中调用此方法。
fixture1
fixture2
setup
applyFixture 方法将 fixture2 的生命周期与 fixture1 的生命周期关联在一起。当测试框架拆解 fixture1 时,还会拆解 fixture2。
applyFixture
示例
f = applyFixture(fixture1,fixture2) 还会在 fixture2 设置完成后将其作为输出返回。
全部展开
matlab.unittest.fixtures.Fixture
主要脚手架,指定为 matlab.unittest.fixtures.Fixture 的实例。
用于设置主要脚手架的脚手架,指定为 matlab.unittest.fixtures.Fixture 的实例。主要脚手架将工作委派给此脚手架。
构造一个脚手架,该脚手架从搜索路径中删除一个文件夹,并在您尝试删除不在该路径上的文件夹时不显示警告。该脚手架使用 SuppressedWarningsFixture 脚手架来禁用指定警告。作为拆解 RemoveFolderFromPathFixture 的一部分,测试框架还会适时清除 SuppressedWarningsFixture,从而将警告状态还原为其先前的值。
SuppressedWarningsFixture
RemoveFolderFromPathFixture
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,从而删除该文件夹及其中的内容。
TemporaryFolderFixture
TemporaryTextFileFixture
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 中推出
applyFixture | matlab.unittest.fixtures
matlab.unittest.fixtures
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
欧洲
亚太
联系您当地的办事处