matlab.unittest.fixtures.CurrentFolderFixture - Fixture for changing current folder - MATLAB (original) (raw)
Main Content
Namespace: matlab.unittest.fixtures
Superclasses: matlab.unittest.fixtures.Fixture
Fixture for changing current folder
Description
The matlab.unittest.fixtures.CurrentFolderFixture
class provides a fixture for changing the current folder. When the testing framework sets up the fixture, the fixture changes the current folder to a specified folder. When the framework tears down the fixture, the fixture changes the current folder back to the original folder.
The matlab.unittest.fixtures.CurrentFolderFixture
class is a handle class.
Creation
Description
fixture = matlab.unittest.fixtures.CurrentFolderFixture(folder)
creates a fixture for changing the current folder to the specified folder and sets the[Folder](matlab.unittest.fixtures.currentfolderfixture-class.html#mw%5F446715af-d2cd-449d-a6cd-eb42ced57907)
property.
Properties
Full path to the target folder, returned as a character vector. Specify the value of this property during creation of the fixture as a string scalar or character vector. You can specify a relative path, but the relative path must be in the current folder. Otherwise, you must specify a full path.
MATLABĀ® throws an error if folder
does not exist.
Attributes:
GetAccess | public |
---|---|
SetAccess | immutable |
Examples
Change the current folder for testing by using aCurrentFolderFixture
instance.
This example assumes that the folder helperFiles
exists in your current folder. Create the folder if it does not exist.
[,] = mkdir("helperFiles")
In a file named CurrentFolderTest.m
in your current folder, create the CurrentFolderTest
class that uses a fixture to change the current folder to helperFiles
. To simplify this example, the test verifies that the full path to the new current folder contains the substring"helperFiles"
.
classdef CurrentFolderTest < matlab.unittest.TestCase methods (Test) function testCurrentFolder(testCase) import matlab.unittest.fixtures.CurrentFolderFixture testCase.applyFixture(CurrentFolderFixture("helperFiles")) testCase.verifySubstring(pwd,"helperFiles") end end end
Before running the CurrentFolderTest
class, first return the path to the current folder. The returned path does not contain"helperFiles"
.
Run the test class. The fixture changes the current folder tohelperFiles
. Therefore, the test passes.
runtests("CurrentFolderTest");
Running CurrentFolderTest . Done CurrentFolderTest
Once the test run is complete, the testing framework tears down the fixture and the environment returns to its original state.
Version History
Introduced in R2013b