matlab.unittest.selectors.HasBaseFolder Class
Namespace: matlab.unittest.selectors
Select TestSuite
array elements by base folder
Description
The matlab.unittest.selectors.HasBaseFolder
class provides a selector for
filtering a test suite based on base folders of tests.
The base folder of a test is the folder that contains the file defining the test. For tests defined in namespaces, the base folder is the parent of the top-level namespace folder.
Creation
Description
Input Arguments
folder
— Name of base folder
string scalar | character vector | matlab.unittest.constraints.Constraint
object
Name of the base folder, specified as a string scalar, character vector, or matlab.unittest.constraints.Constraint
object. Test selection by base
folder is subject to these conditions:
If you specify a string scalar or character vector, the base folder of the test must be the same as the specified value. The specified value must be a full path.
If you specify a constraint, the base folder of the test must satisfy the constraint.
This argument sets the Constraint
property.
Properties
Constraint
— Condition that base folder must satisfy
matlab.unittest.constraints.Constraint
object
Condition that the base folder must satisfy for the test to be included in the
filtered test suite, returned as a matlab.unittest.constraints.Constraint
object.
This property is set by the folder
input argument:
If you specify a string scalar or character vector, the testing framework sets the property to the
IsEqualTo
constraint with the expected value as the specified base folder.If you specify a constraint, the testing framework sets the property to the constraint.
Attributes:
GetAccess | public |
SetAccess | immutable |
Examples
Select Tests by Base Folder
Create filtered test suites by selecting tests using the
HasBaseFolder
class. To simplify the test code, the test classes in this
example use unconditional test failures as placeholders for unimplemented tests.
In your current folder, create a folder named myTests
. Then
create two folders, feature1
and feature2
, in
myTests
.
In a file named Feature1Test.m
in the feature1
folder, create the Feature1Test
class.
classdef Feature1Test < matlab.unittest.TestCase methods (Test) function defaultBehavior(testCase) testCase.verifyFail("Add code to test default behavior.") end function otherBehavior(testCase) testCase.verifyFail("Add code to test nondefault behavior.") end end end
In a file named Feature2Test.m
in the feature2
folder, create the Feature2Test
class.
classdef Feature2Test < matlab.unittest.TestCase methods (Test) function defaultBehavior(testCase) testCase.verifyFail("Add code to test default behavior.") end function otherBehavior(testCase) testCase.verifyFail("Add code to test nondefault behavior.") end end end
Import the classes used in this example.
import matlab.unittest.TestSuite import matlab.unittest.selectors.HasBaseFolder import matlab.unittest.constraints.ContainsSubstring
Make sure that your current folder is the parent folder of
myTests
. Create a test suite from the myTests
folder and its subfolders. Then, display the names of the TestSuite
array
elements. The test suite contains the tests defined in the feature1
and feature2
folders.
suite = testsuite("myTests","IncludingSubfolders",true); disp({suite.Name}')
{'Feature1Test/defaultBehavior'} {'Feature1Test/otherBehavior' } {'Feature2Test/defaultBehavior'} {'Feature2Test/otherBehavior' }
Select all the tests that are defined in the feature1
folder.
suite1 = suite.selectIf(HasBaseFolder( ... fullfile(pwd,"myTests","feature1"))); disp({suite1.Name}')
{'Feature1Test/defaultBehavior'} {'Feature1Test/otherBehavior' }
Select all the tests in suite
that are defined outside of
feature1
. The filtered test suite contains only the tests defined
in the feature2
folder.
suite2 = suite.selectIf(~HasBaseFolder( ... fullfile(pwd,"myTests","feature1"))); disp({suite2.Name}')
{'Feature2Test/defaultBehavior'} {'Feature2Test/otherBehavior' }
Create a filtered test suite directly from myTests
and its
subfolders by including only tests whose base folder contains the substring
"2"
.
suite3 = TestSuite.fromFolder("myTests", ... HasBaseFolder(ContainsSubstring("2")), ... "IncludingSubfolders",true); disp({suite3.Name}')
{'Feature2Test/defaultBehavior'} {'Feature2Test/otherBehavior' }
Version History
Introduced in R2014a
See Also
selectIf
| testsuite
| matlab.unittest.TestSuite
| matlab.unittest.Test
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)