This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

matlab.unittest.fixtures.CurrentFolderFixture class

Package: matlab.unittest.fixtures

Fixture for changing current working folder


The 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.


matlab.unittest.fixtures.CurrentFolderFixture(folder) constructs a fixture for changing the current working folder to folder.

Input Arguments

expand all

Folder to make the current working folder, specified as a character vector. MATLAB® throws an error if folder does not exist.



Folder to make the current working folder, specified as a character vector in the folder input argument.

Copy Semantics

Handle. To learn how handle classes affect copy operations, see Copying Objects.


expand all

Create the following changeFolderFixtureTest class definition on your MATLAB path. This example assumes that the subfolder helperFiles exists in your working folder. Create the changeToFolderin your working folder if it does not exist.

The test1 function includes a call to pwd to demonstrate the current path changed to the helperFiles folder.

classdef changeFolderFixtureTest < matlab.unittest.TestCase
        function test1(testCase)
            import matlab.unittest.fixtures.CurrentFolderFixture
            changeToFolder = 'helperFiles';
            testCase.applyFixture(CurrentFolderFixture ...

At the command prompt, run the test. For the purposes of this example, call pwd before and after run to show the fixture was properly torn down and the path returned to the pre-test state.

currentFolderBeforeTest = pwd
currentFolderAfterTest = pwd
currentFolderBeforeTest =


Running changeFolderFixtureTest

ans =


Done changeFolderFixtureTest

currentFolderAfterTest =

Was this topic helpful?