MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

Define Pairwise Parameterized Test Methods


Define a methods block with the Test and ParameterCombination='pairwise'
attributes. The test framework invokes these methods at least once for every pair of
property values.


methods (Test, ParameterCombination='pairwise')
function testRepeatable(testCase,dim1,dim2,dim3)
state = rng;
firstRun = rand(dim1,dim2,dim3);
rng(state)
secondRun = rand(dim1,dim2,dim3);
testCase.verifyEqual(firstRun,secondRun)
end
end


The test method verifies that the random number generator results are repeatable. For a
given TestClassSetup and TestMethodSetup parameterization, the framework calls
the testRepeatble method 10 times to ensure testing of each pair of dim1, dim2, and
dim3. However, if the parameter combination attribute is exhaustive, the framework calls
the method 3^3=27 times.


Define Exhaustive Parameterized Test Methods


Define a methods block with the Test attribute or no defined parameter combination.
The parameter combination is exhaustive by default. The test framework invokes these
methods once for every combination of property values.


methods (Test)
function testClass(testCase,dim1,dim2,type)
testCase.verifyClass(rand(dim1,dim2,type), type)
end
end


The test method verifies that the class of the output from rand is the same as the
expected class. For a given TestClassSetup and TestMethodSetup parameterization,
the framework calls the testClass method 332=18 times to ensure testing of each
combination of dim1, dim2, and type.


TestRand Class Definition Summary


classdef TestRand < matlab.unittest.TestCase
properties (ClassSetupParameter)
generator = {'twister','combRecursive','multFibonacci'};


Create Advanced Parameterized Test
Free download pdf