Can you specify which value TestParameter properties take in a class-based unit performance test?
3 views (last 30 days)
Show older comments
E.g. say I have the following performance test class:
classdef MyPerftest < matlab.perftest.TestCase
properties (TestParameter)
A = {1,2,3}
B = {4,5,6}
end
methods (Test)
function myTest(testCase, A,B)
C = A+B;
end
end
end
Now in the command line, could I call it so that it executes the test using only the first value of A, and the first value of B? I know you can do this:
runperf('MyPerftest/myTest')
which will go through every combination of A and B, but is there a way to test only one combination at a time?
0 Comments
Answers (1)
Andy Campbell
on 26 Dec 2019
Hello Jai,
Yes you can create the suite using the name of the indidivual test directly, or use other name/value pairs to select the test you want.
To see what the name of each test create the suite and look at the Name property:
>> s = testsuite('MyPerftest');
>> {s.Name}'
ans =
9×1 cell array
{'MyPerftest/myTest(A=value1,B=value1)'}
{'MyPerftest/myTest(A=value1,B=value2)'}
{'MyPerftest/myTest(A=value1,B=value3)'}
{'MyPerftest/myTest(A=value2,B=value1)'}
{'MyPerftest/myTest(A=value2,B=value2)'}
{'MyPerftest/myTest(A=value2,B=value3)'}
{'MyPerftest/myTest(A=value3,B=value1)'}
{'MyPerftest/myTest(A=value3,B=value2)'}
{'MyPerftest/myTest(A=value3,B=value3)'}
>>
Note that since you only include the values of the paraemeter the names are not terribly descriptive. You can makeit more descriptive by using the struct form to create the parameters which allows you to label each parameter point. For example:
classdef MyPerftest < matlab.perftest.TestCase
properties (TestParameter)
A = struct("small",1, "medium", 2, "large", 3);
B = createBParams;
end
methods (Test)
function myTest(testCase, A,B)
C = A+B;
end
end
end
function b = createBParams
b.first = 4;
b.middle = 5;
b.last = 6;
end
These labels are then used in the names and you can run them directly:
>> s = testsuite('MyPerftest');
{s.Name}'
ans =
9×1 cell array
{'MyPerftest/myTest(A=small,B=first)' }
{'MyPerftest/myTest(A=small,B=middle)' }
{'MyPerftest/myTest(A=small,B=last)' }
{'MyPerftest/myTest(A=medium,B=first)' }
{'MyPerftest/myTest(A=medium,B=middle)'}
{'MyPerftest/myTest(A=medium,B=last)' }
{'MyPerftest/myTest(A=large,B=first)' }
{'MyPerftest/myTest(A=large,B=middle)' }
{'MyPerftest/myTest(A=large,B=last)' }
>> runperf("MyPerftest/myTest(A=medium,B=last)")
Running MyPerftest
.......... .......... ..
Done MyPerftest
__________
ans =
TimeResult with properties:
Name: 'MyPerftest/myTest(A=medium,B=last)'
Valid: 1
Samples: [18×7 table]
TestActivity: [22×12 table]
Totals:
1 Valid, 0 Invalid.
0.023728 seconds testing time.
>>
0 Comments
See Also
Categories
Find more on Write Unit Tests in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!