Several of the tests in class ExampleTagTest are tagged. For example, testD is tagged
with 'Unit' and 'FeatureA'. One test, testA, is not tagged.
This sample test class, ExampleTagClassTest, uses a TestTags class attribute to tag
all the tests within the class, and a TestTags method attribute to add tags to individual
tests.
classdef (TestTags = {'FeatureB'}) ...
ExampleTagClassTest < matlab.unittest.TestCase
methods (Test)
function testF (testCase)
% test code
end
end
methods (Test, TestTags = {'FeatureC','System'})
function testG (testCase)
% test code
end
end
methods (Test, TestTags = {'System','FeatureA'})
function testH (testCase)
% test code
end
end
end
Each test in class ExampleTagClassTest is tagged with 'FeatureB'. Additionally,
individual tests are tagged with various tags including 'FeatureA', 'FeatureC', and
'System'.
Select and Run Tests
There are three ways of selecting and running tagged tests:
- “Run Selected Tests Using runtests” on page 33-64
- “Select Tests Using TestSuite Methods” on page 33-65
- “Select Tests Using HasTag Selector” on page 33-66
Run Selected Tests Using runtests
Use the runtests function to select and run tests without explicitly creating a test suite.
Select and run all the tests from ExampleTagTest and ExampleTagClassTest that
include the 'FeatureA' tag.
33 Unit Testing