Hi DAX,
You can create Shared test fixture class that loads dataToProcess and runs the TestExample suite.
Using fixtures is more efficient in my experience. You can see more on creating shared test fixtures here: Write Tests Using Shared Fixtures
Alternatively, if you want to manually group and monitor how data is being consumed by tests running in parallel here is a quick workaround you can try:
Simplify and move dataToProcess part outside of Test Example
classdef TestExample < matlab.unittest.TestCase
properties(Access=private)
res1;
res2;
res3;
end
methods(TestClassSetup)
function setup(obj)
obj.res1=1;
obj.res2=2;
obj.res3=3;
end
end
methods(Test)
function test1(obj)
disp('test1');
obj.verifyEqual(obj.res1,1);
end
function test2(obj)
disp('test2');
obj.verifyEqual(obj.res2,2);
end
function test3(obj)
disp('test3');
obj.verifyEqual(obj.res3,3);
end
end
end
Have a ManuallyGroupedTests class that runs tests from TestExample
classdef ManuallyGroupedTests < matlab.unittest.TestCase
properties(ClassSetupParameter)
dataToProcess = {'DataA','DataB','DataC','DataD','DataE'};
end
methods(TestClassSetup)
function setup(~, dataToProcess)
disp(dataToProcess);
end
end
methods(Test)
function test(~)
r = matlab.unittest.TestRunner.withTextOutput;
ts = matlab.unittest.TestSuite.fromFile('TestExample.m');
r.run(ts);
end
end
end
To run tests in parallel
clc;
tic;
ts=matlab.unittest.TestSuite.fromClass(?ManuallyGroupedTests);
r=matlab.unittest.TestRunner.withTextOutput();
r.runInParallel(ts);
toc;
Regards,
Sujay