function testFunctionOne(testCase)
% Test specific code
end
function FunctionTwotest(testCase)
% Test specific code
end
Create Optional Fixture Functions
Setup and teardown code, also referred to as test fixture functions, set up the pretest
state of the system and return it to the original state after running the test. There are two
types of these functions: file fixture functions that run once per test file, and fresh fixture
functions that run before and after each local test function. These functions are not
required to generate tests. In general, it is preferable to use fresh fixtures over file
fixtures to increase unit test encapsulation.
A function test case object, testCase, must be the only input to file fixture and fresh
fixture functions. The Unit Test Framework automatically generates this object. The
TestCase object is a means to pass information between setup functions, test functions,
and teardown functions. Its TestData property is, by default, a struct, which allows
easy addition of fields and data. Typical uses for this test data include paths and graphics
handles. For an example using the TestData property, see “Write Test Using Setup and
Teardown Functions” on page 33-35.
File Fixture Functions
Use file fixture functions to share setup and teardown functions across all the tests in a
file. The names for the file fixture functions must be setupOnce and teardownOnce,
respectively. These functions execute a single time for each file. You can use file fixtures
to set a path before testing, and then reset it to the original path after testing. This is a
typical example of skeletal file fixture setup and teardown code.
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
33 Unit Testing