Test Selection
With an explicit test suite, use selectors to refine your suite. Several of the selectors are
applicable only for class-based tests, but you can select tests for your suite based on the
test name:- Use the 'Name' name-value pair argument in a suite generation method, such as
fromFile. - Use a selectors instance and optional constraints instance.
Use these approaches in a suite generation method, such as fromFile, or create a suite
and filter it using the TestSuite.selectIf method. For example, in this listing, the
four values of suite are equivalent.import matlab.unittest.selectors.HasName
import matlab.unittest.constraints.ContainsSubstring
import matlab.unittest.TestSuite.fromFilef = 'rightTriTolTest.m';
selector = HasName(ContainsSubstring('Triangle'));% fromFile, name-value pair
suite = TestSuite.fromFile(f,'Name','*Triangle*')% fromFile, selector
suite = TestSuite.fromFile(f,selector)% selectIf, name-value pair
fullSuite = TestSuite.fromFile(f);
suite = selectIf(fullSuite,'Name','*Triangle*')% selectIf, selector
fullSuite = TestSuite.fromFile(f);
suite = selectIf(fullSuite,selector)If you use one of the suite creation methods with a selector or name-value pair, the
testing framework creates the filtered suite. If you use the TestSuite.selectIf
method, the testing framework creates a full test suite and then filters it. For large test
suites, this approach can have performance implications.33 Unit Testing