matlab.unittest.selectors.HasBaseFolder - Select TestSuite array elements by base folder - MATLAB (original) (raw)
Main Content
Namespace: matlab.unittest.selectors
Superclasses: matlab.unittest.selectors.Selector
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
selector = matlab.unittest.selectors.HasBaseFolder([folder](#mw%5F9ce7bc61-d3cb-458e-a607-79c37b046b4b))
creates a selector that selects TestSuite array elements whose base folder matches the specified value.
Input Arguments
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](matlab.unittest.selectors.hasbasefolder-class.html#mw%5F0c81f748-89f4-467d-a7e3-5467060bc87c)
property.
Properties
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
Create filtered test suites by selecting tests using theHasBaseFolder
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
, inmyTests
.
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 ofmyTests
. 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 offeature1
. 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