matlab.unittest.parameters.Parameter Class
Namespace: matlab.unittest.parameters
Base class for parameters
Description
In parameterized testing, use parameters to pass data to test methods.
Construction
Instantiate a Parameter
using the static fromData
method.
Properties
Property
— Name of property that defines Parameter
character vector
This property is read-only.
Name of the property that defines the Parameter
, stored as a
character vector.
Name
— Parameter value name
character vector
This property is read-only.
Parameter value name, stored as a character vector. Name
uniquely identifies a particular value for a parameter.
Value
— Parameter value
any type of array
This property is read-only.
Parameter value, stored as any type of array. Value
holds the
data that the TestRunner
passes into a parameterized method.
Methods
fromData | Create parameters from data |
Copy Semantics
Value. To learn how value classes affect copy operations, see Copying Objects.
Examples
Test Using Parameters External to Test Class
In your working folder, create testZeros.m
. This class contains five test methods, resulting in eleven parameterized tests.
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
Redefine the type
parameter so that the test uses uint64
and int64
data types in the parameterization instead of single
, double
, and uint16
. Create parameters.
import matlab.unittest.parameters.Parameter newType = {'int64','uint64'}; param = Parameter.fromData('type',newType);
Create a test suite that injects the param
parameters. View the names of the tests in the suite. The injected parameters are indicated by #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' }
Run the suite.
results = suite.run;
Running testZeros ......... Done testZeros __________
Redefine the outSize
parameter so that the test parameterizes for 1-d and 4-d arrays. Create parameters from newType
and newSize
.
newSize = struct('s2d',[5 3],'s4d',[2 3 2 4]); param = Parameter.fromData('type',newType,'outSize',newSize);
Create a test suite that injects the param
parameters. View the names of the tests in the suite. The injected parameters are indicated by #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' }
Run the suite.
results = suite.run;
Running testZeros ......... Done testZeros __________
Version History
Introduced in R2018b
See Also
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.
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)