matlab.unittest.fixtures.PathFixture - Fixture for adding folders to the MATLAB path - MATLAB (original) (raw)
Namespace: matlab.unittest.fixtures
Superclasses: matlab.unittest.fixtures.Fixture
Fixture for adding folders to the MATLAB path
Description
The matlab.unittest.fixtures.PathFixture
class provides a fixture for adding folders to the MATLABĀ® path. When the testing framework sets up the fixture, the fixture adds the specified folders to the path. When the framework tears down the fixture, the fixture restores the path to its original state.
The matlab.unittest.fixtures.PathFixture
class is a handle class.
Creation
Description
fixture = matlab.unittest.fixtures.PathFixture([folders](#mw%5Fb32502e2-a9a3-4201-b07d-94a4a9de2e92))
creates a fixture for adding the specified folders to the path.
fixture = matlab.unittest.fixtures.PathFixture([folders](#mw%5Fb32502e2-a9a3-4201-b07d-94a4a9de2e92),[Name,Value](#namevaluepairarguments))
sets additional options using one or more name-value arguments. For example,fixture = matlab.unittest.fixtures.PathFixture("myFolder","IncludingSubfolders",true)
creates a fixture that adds myFolder
and all of its subfolders to the path.
Input Arguments
Folders to add to the path, specified as a string array, character vector, or cell array of character vectors. You can specify a folder in folders
with a relative path, but the relative path must be in the current folder. Otherwise, you must use a full path to specify the folder. If any of the specified folders does not exist, MATLAB throws an error.
This argument sets the [Folders](matlab.unittest.fixtures.pathfixture-class.html#mw%5F42378041-5742-4dd4-897e-05fdb79ea5ea)
property.
Name-Value Arguments
Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN
, where Name
is the argument name and Value
is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.
Example: fixture = matlab.unittest.fixtures.PathFixture("myFolder",IncludingSubfolders=true)
Before R2021a, use commas to separate each name and value, and enclose Name
in quotes.
Example: fixture = matlab.unittest.fixtures.PathFixture("myFolder","IncludingSubfolders",true)
Whether to include the subfolders of folders on the path, specified as a numeric or logical 0
(false
) or 1
(true
). By default, the fixture does not include the subfolders of folders
on the path.
Class, namespace, private
, and resources
subfolders cannot be included on the path, even when the value istrue
.
This argument sets the [IncludeSubfolders](matlab.unittest.fixtures.pathfixture-class.html#mw%5F9b171ce8-2c53-4be3-93e5-bbb05487636e)
property.
Where on the path to add the folders, specified as "begin"
or"end"
. By default, the fixture adds folders to the beginning (top) of the path. If you specify the value as"end"
, the fixture adds folders
to the end (bottom) of the path.
If you specify this argument along withIncludingSubfolders
, the fixture adds the specified folders and their subfolders to the top or bottom of the path as a single block.
This argument sets the [Position](matlab.unittest.fixtures.pathfixture-class.html#mw%5F162fcbb5-2923-480e-bf20-4365cbf5ae06)
property.
Properties
Full paths to the folders to add to the path, returned as a string array.
This property is set by the folders input argument.
Attributes:
GetAccess | public |
---|---|
SetAccess | private |
Whether to include subfolders on the path, returned as a logical0
(false
) or 1
(true
). By default, the fixture does not include subfolders on the path.
This property is set by the IncludingSubfolders name-value argument.
Attributes:
GetAccess | public |
---|---|
SetAccess | immutable |
Where on the path to add the folders, returned as 'begin'
or'end'
. By default, the fixture adds the folders to the top of the path.
This property is set by the Position name-value argument.
Attributes:
GetAccess | public |
---|---|
SetAccess | immutable |
Examples
Temporarily add folders to the path for testing by using a PathFixture
instance.
This example assumes that folderA
and folderB
exist in your current folder. Create the folders if they do not exist.
[,] = mkdir("folderA")
[,] = mkdir("folderB")
In a file named PathFixtureTest.m
in your current folder, create the PathFixtureTest
class. The test uses a PathFixture
instance to add folderA
and folderB
to the path. Then, it verifies that the path contains the names of the folders.
classdef PathFixtureTest < matlab.unittest.TestCase methods (Test) function testPath(testCase) import matlab.unittest.fixtures.PathFixture import matlab.unittest.constraints.ContainsSubstring f = testCase.applyFixture(PathFixture(["folderA" "folderB"])); testCase.verifyThat(path,ContainsSubstring(f.Folders(1))) testCase.verifyThat(path,ContainsSubstring(f.Folders(2))) end end end
Run the test. Because both folderA
and folderB
are on the path, the test passes. After testing, the framework tears down the fixture, which restores the path to its previous state.
runtests("PathFixtureTest");
Running PathFixtureTest . Done PathFixtureTest
Version History
Introduced in R2013b