Apply Custom Fixture as Shared FixtureIn your working folder, create three test classes using a shared fixture. Using a shared
fixture allows the UserNameEnvironmentVariableFixture to be shared across
classes.Create testA.m as follows.classdef (SharedTestFixtures={...
UserNameEnvironmentVariableFixture('David')}) ...
testA < matlab.unittest.TestCase
methods (Test)
function t1(~)
fprintf(1, 'Current UserName: "%s"', getenv('UserName'))
end
end
endCreate testB.m as follows.classdef (SharedTestFixtures={...
UserNameEnvironmentVariableFixture('Andy')}) ...
testB < matlab.unittest.TestCase
methods (Test)
function t1(~)
fprintf(1, 'Current UserName: "%s"', getenv('UserName'))
end
end
endCreate testC.m as follows.classdef (SharedTestFixtures={...
UserNameEnvironmentVariableFixture('Andy')}) ...
testC < matlab.unittest.TestCase
methods (Test)
function t1(~)
fprintf(1, 'Current UserName: "%s"', getenv('UserName'))
end
end
endAt the command prompt, run the tests.runtests({'testA','testB','testC'});33 Unit Testing