matlab.unittest.parameters.Parameter 类
命名空间: matlab.unittest.parameters
参数的基类
描述
在参数化测试中,使用参数将数据传递给测试方法。
构造
使用静态 fromData
方法实例化 Parameter
。
属性
Property
— 用于定义 Parameter
的属性的名称
字符向量
此 属性 为只读。
用于定义 Parameter
的属性的名称,存储为字符向量。
Name
— 参数值名称
字符向量
此 属性 为只读。
参数值名称,存储为字符向量。Name
唯一标识参数的特定值。
Value
— 参数值
任何类型的数组
此 属性 为只读。
参数值,存储为任何类型的数组。Value
保存 TestRunner
传递给参数化方法的数据。
方法
fromData | 从数据创建参数 |
复制语义
值。要了解值类如何影响复制操作,请参阅复制对象。
示例
使用测试类的外部参数进行测试
在您的工作文件夹中,创建 testZeros.m
。该类包含五个测试方法,产生十一个参数化测试。
classdef testZeros < matlab.unittest.TestCase properties (TestParameter) type = {'single','double','uint16'}; outSize = struct('s2d',[3 3], 's3d',[2 5 4]); end methods (Test) function testClass(testCase, type, outSize) testCase.verifyClass(zeros(outSize,type), type); end function testSize(testCase, outSize) testCase.verifySize(zeros(outSize), outSize); end function testDefaultClass(testCase) testCase.verifyClass(zeros, 'double'); end function testDefaultSize(testCase) testCase.verifySize(zeros, [1 1]); end function testDefaultValue(testCase) testCase.verifyEqual(zeros,0); end end end
重新定义 type
参数,以便测试在参数化中使用 uint64
和 int64
数据类型,而不是 single
、double
和 uint16
。创建参数。
import matlab.unittest.parameters.Parameter newType = {'int64','uint64'}; param = Parameter.fromData('type',newType);
创建注入 param
参数的测试套件。查看该套件中测试的名称。注入的参数由 #ext
指示。
import matlab.unittest.TestSuite suite = TestSuite.fromClass(?testZeros,'ExternalParameters',param); {suite.Name}'
ans = 9×1 cell array {'testZeros/testClass(type=int64#ext,outSize=s2d)' } {'testZeros/testClass(type=int64#ext,outSize=s3d)' } {'testZeros/testClass(type=uint64#ext,outSize=s2d)'} {'testZeros/testClass(type=uint64#ext,outSize=s3d)'} {'testZeros/testSize(outSize=s2d)' } {'testZeros/testSize(outSize=s3d)' } {'testZeros/testDefaultClass' } {'testZeros/testDefaultSize' } {'testZeros/testDefaultValue' }
运行该套件。
results = suite.run;
Running testZeros ......... Done testZeros __________
重新定义 outSize
参数,以便测试参数化一维和四维数组。从 newType
和 newSize
创建参数。
newSize = struct('s2d',[5 3],'s4d',[2 3 2 4]); param = Parameter.fromData('type',newType,'outSize',newSize);
创建注入 param
参数的测试套件。查看该套件中测试的名称。注入的参数由 #ext
指示。
import matlab.unittest.TestSuite suite = TestSuite.fromClass(?testZeros,'ExternalParameters',param); {suite.Name}'
ans = 9×1 cell array {'testZeros/testClass(type=int64#ext,outSize=s2d#ext)' } {'testZeros/testClass(type=int64#ext,outSize=s4d#ext)' } {'testZeros/testClass(type=uint64#ext,outSize=s2d#ext)'} {'testZeros/testClass(type=uint64#ext,outSize=s4d#ext)'} {'testZeros/testSize(outSize=s2d#ext)' } {'testZeros/testSize(outSize=s4d#ext)' } {'testZeros/testDefaultClass' } {'testZeros/testDefaultSize' } {'testZeros/testDefaultValue' }
运行该套件。
results = suite.run;
Running testZeros ......... Done testZeros __________
版本历史记录
在 R2018b 中推出
另请参阅
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)