MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

  • Test class: TestRand

  • Class setup property and property name: [generator=twister]

  • Method setup property and property name: [seed=value1]

  • Test method name: testClass

  • Test method properties and property names:
    (dim1=small,dim2=small,type=single)


The name for the seed property isn’t particularly meaningful (value1). The testing
framework provided this name because the seed property values are numbers. For a
more meaningful name, define the seed property as a struct with more descriptive field
names.

Run Suite from Class Using Selector

At the command prompt, create a selector to select test elements that test the
'twister' generator for 'single' precision. Omit test elements that use properties
with the 'large' name.

import matlab.unittest.selectors.HasParameter
s = HasParameter('Property','generator', 'Name','twister') & ...
HasParameter('Property','type', 'Name','single') & ...
~HasParameter('Name','large');

suite2 = matlab.unittest.TestSuite.fromClass(?TestRand,s)

suite2 =

1×12 Test array with properties:

Name
ProcedureName
TestClass
BaseFolder
Parameterization
SharedTestFixtures
Tags

Tests Include:
9 Unique Parameterizations, 0 Shared Test Fixture Classes, 0 Tags.

If you first generate the full suite, construct the same test suite as above using the
selectIf method.

33 Unit Testing

Free download pdf