type = {'single','double'};
end
Define Test Class and Test Method Setup Methods
Define the setup methods at the test class and test method level. These methods register
the initial random number generator state. After the framework runs the tests, the
methods restore the original state. The ClassSetup method defines the type of random
number generator, and the TestMethodSetup seeds the generator.
methods (TestClassSetup)
function ClassSetup(testCase, generator)
orig = rng;
testCase.addTeardown(@rng, orig)
rng(0, generator)
end
end
methods (TestMethodSetup)
function MethodSetup(testCase, seed)
orig = rng;
testCase.addTeardown(@rng, orig)
rng(seed)
end
end
Define Sequential Parameterized Test Methods
Define a methods block with the Test and ParameterCombination='sequential'
attributes. The test framework invokes these methods once for each corresponding
property value.
methods (Test, ParameterCombination='sequential')
function testSize(testCase,dim1,dim2,dim3)
testCase.verifySize(rand(dim1,dim2,dim3),[dim1 dim2 dim3])
end
end
The method tests the size of the output for each corresponding parameter in dim1, dim2,
and dim3. For example, to test all the 'medium' values use:
testCase.verifySize(rand(2,3,4),[2 3 4]);. For a given TestClassSetup and
TestMethodSetup parameterization, the framework calls the testSize method three
times—once each for the 'small', 'medium', and 'large' values.
33 Unit Testing