I am trying to create a parameterized Matlab unittest where TestParameter properties TestParameter generated βdynamicallyβ by some code (for example, with a for loop).
As a simplified example, suppose my code
classdef partest < matlab.unittest.TestCase properties (TestParameter) level = struct('level1', 1, 'level2', 2, 'level3', 3, 'level4', 4) end methods (Test) function testModeling(testCase, level) fprintf('Testing level %d\n', level); end end end
but in my real code I have 100 levels. I tried putting this in a separate method like
classdef partest < matlab.unittest.TestCase methods (Static) function level = getLevel() for i=1:100 level.(sprintf('Level%d', i)) = i; end end end properties (TestParameter) level = partest.getLevel() end methods (Test) function testModeling(testCase, level) fprintf('Testing level %d\n', level); end end end
but it does not work; I get an error (Matlab 2014b):
>> runtests partest Error using matlab.unittest.TestSuite.fromFile (line 163) The class partest has no property or method named 'getLevel'.
I could move the getLevel() function to another file, but I would like to save it in one file.
source share