Fixture for changing current working folder
CurrentFolderFixture class provides a
fixture for changing the current working folder. When the test framework
sets up the fixture, it changes the working folder. When the test
framework tears down the fixture, it restores the working folder to
its previous state.
a fixture for changing the current working folder to
Folder to make the current working folder, specified as a string
Handle. To learn how handle classes affect copy operations, see Copying Objects in the MATLAB documentation.
Create the following
definition on your MATLAB path. This example assumes that the
helperFiles exists in your working folder.
changeToFolderin your working folder
if it does not exist.
test1 function includes a call to
demonstrate the current path changed to the
classdef changeFolderFixtureTest < matlab.unittest.TestCase methods(Test) function test1(testCase) import matlab.unittest.fixtures.CurrentFolderFixture changeToFolder = 'helperFiles'; testCase.applyFixture(CurrentFolderFixture ... (changeToFolder)); pwd end end end
At the command prompt, run the test. For the purposes
of this example, call
pwd before and after
show the fixture was properly torn down and the path returned to the
currentFolderBeforeTest = pwd run(changeFolderFixtureTest); currentFolderAfterTest = pwd
currentFolderBeforeTest = H:\Documents\doc_examples Running changeFolderFixtureTest ans = H:\Documents\doc_examples\helperFiles . Done changeFolderFixtureTest __________ currentFolderAfterTest = H:\Documents\doc_examples