matlab.unittest.parameters.Parameter 类
命名空间: matlab.unittest.parameters
参数的基类
描述
在参数化测试中,使用参数将数据传递给测试方法。
构造
使用静态 fromData 方法实例化 Parameter。
属性
此 属性 为只读。
用于定义 Parameter 的属性的名称,存储为字符向量。
此 属性 为只读。
参数值名称,存储为字符向量。Name 唯一标识参数的特定值。
此 属性 为只读。
参数值,存储为任何类型的数组。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 Command
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 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)