getSharedTestFixtures
类: matlab.unittest.TestCase
命名空间: matlab.unittest
提供对共享测试脚手架的访问权限
语法
说明
fixtures = getSharedTestFixtures(
提供对测试用例的共享测试脚手架的访问,并将它们以 testCase
)matlab.unittest.fixtures.Fixture
对象数组形式返回。共享测试脚手架是使用 TestCase
子类的 SharedTestFixtures
属性指定的。
fixtures = getSharedTestFixtures(
只返回其类名称为 testCase
,fixtureClassName
)fixtureClassName
的共享测试脚手架。
输入参数
testCase
— 测试用例
matlab.unittest.TestCase
对象
测试用例,指定为 matlab.unittest.TestCase
对象。
fixtureClassName
— 定义脚手架的类的名称
字符串标量 | 字符向量
定义共享测试脚手架的类的完全限定名称,指定为字符串标量或字符向量。
示例: "matlab.unittest.fixtures.PathFixture"
示例
访问共享测试脚手架
使用 getSharedTestFixtures
方法访问测试中的共享脚手架。
此示例假设您的当前文件夹中包含名为 helperFiles
的子文件夹。如果该子文件夹不存在,请创建它。
[~,~] = mkdir("helperFiles")
在您的当前文件夹下的文件中,创建使用两个共享测试脚手架的 SampleTest
检验类。为了说明目的,在此示例中,Test
方法访问这些脚手架来执行其鉴定。
classdef (SharedTestFixtures={ ... matlab.unittest.fixtures.PathFixture("helperFiles"), ... matlab.unittest.fixtures.TemporaryFolderFixture}) ... SampleTest < matlab.unittest.TestCase methods (Test) function testFixtureCount(testCase) % Test the number of shared test fixtures f = testCase.getSharedTestFixtures; testCase.verifyNumElements(f,2) end function testPath(testCase) % Test the search path import matlab.unittest.constraints.ContainsSubstring f = testCase.getSharedTestFixtures( ... "matlab.unittest.fixtures.PathFixture"); testCase.verifyThat(path,ContainsSubstring(f.Folder)) end function testTempFolder(testCase) % Test writing to the temporary folder import matlab.unittest.constraints.IsFile f = testCase.getSharedTestFixtures( ... "matlab.unittest.fixtures.TemporaryFolderFixture"); tempFolderName = f.Folder; filename = string(tempFolderName) + filesep + "myFile.dat"; writematrix(magic(20),filename) testCase.verifyThat(filename,IsFile) end end end
运行测试类。测试框架首先设置脚手架,运行测试,然后拆解脚手架。在此示例中,所有测试都通过。
results = runtests("SampleTest");
Setting up PathFixture Done setting up PathFixture: Added 'C:\work\helperFiles' to the path. __________ Setting up TemporaryFolderFixture Done setting up TemporaryFolderFixture: Created the temporary folder "C:\Temp\tpf8cf6d27_3c19_42ce_9c0f_d3a130a077f0". __________ Running SampleTest ... Done SampleTest __________ Tearing down TemporaryFolderFixture Done tearing down TemporaryFolderFixture: Deleted the temporary folder "C:\Temp\tpf8cf6d27_3c19_42ce_9c0f_d3a130a077f0" and all its contents. __________ Tearing down PathFixture Done tearing down PathFixture: Restored the path to its original state. __________
版本历史记录
在 R2013b 中推出
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)