Fresh Fixture Functions
Use fresh fixture functions to set up and tear down states for each local test function. The
names for these fresh fixture functions must be setup and teardown, respectively. You
can use fresh fixtures to obtain a new figure before testing and to close the figure after
testing. This is typical example of skeletal test function level setup and teardown code.
function setup(testCase) % do not change function name
% open a figure, for example
end
function teardown(testCase) % do not change function name
% close figure, for example
end
Program Listing Template
%% Main function to generate tests
function tests = exampleTest
tests = functiontests(localfunctions);
end
%% Test Functions
function testFunctionOne(testCase)
% Test specific code
end
function FunctionTwotest(testCase)
% Test specific code
end
%% Optional file fixtures
function setupOnce(testCase) % do not change function name
% set a new path, for example
end
function teardownOnce(testCase) % do not change function name
% change back to original path, for example
end
%% Optional fresh fixtures
function setup(testCase) % do not change function name
% open a figure, for example
end
Write Function-Based Unit Tests