Use fixture with
the specified fixture for use with the
This method enables the use of a fixture within the scope of a single
TestCase class. The life cycle of the fixture
is tied to the
TestCase. When the
out of scope, the test framework tears down the fixture.
applyFixture within a
TestMethodSetup method to use a fixture for
the current test method alone. Use
TestClassSetup method to set up a fixture for
the entire class.
Create a temporary folder and make it the current working folder.
classdef applyFixtureTest < matlab.unittest.TestCase methods(TestMethodSetup) function addHelpers(testCase) import matlab.unittest.fixtures.TemporaryFolderFixture; import matlab.unittest.fixtures.CurrentFolderFixture; % Create a temporary folder and make it the current working % folder. tempFolder = testCase.applyFixture(TemporaryFolderFixture); testCase.applyFixture(CurrentFolderFixture(tempFolder.Folder)); end end end
Each test method can write files to the current working folder, which is the temporary folder. After each test method runs, the test framework restores the working folder to its previous state and deletes the temporary folder.