MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
suite = [sA sB];
{suite.Name}'

ans =

3×1 cell array

'ExampleTagTest/testE'
'ExampleTagTest/testD'
'ExampleTagClassTest/testG'

Select Tests Using HasTag Selector

Create a suite of all the tests from the ExampleTagTest and ExampleTagClassTest
classes.

import matlab.unittest.selectors.HasTag
sA = TestSuite.fromClass(?ExampleTagTest);
sB = TestSuite.fromFile('ExampleTagClassTest.m');
suite = [sA sB];

Select all the tests that do not have tags.

s1 = suite.selectIf(~HasTag)

s1 =

Test with properties:

Name: 'ExampleTagTest/testA'
ProcedureName: 'testA'
TestClass: "ExampleTagTest"
BaseFolder: 'C:\work'
Parameterization: [0×0 matlab.unittest.parameters.EmptyParameter]
SharedTestFixtures: [0×0 matlab.unittest.fixtures.EmptyFixture]
Tags: {1×0 cell}

Tests Include:
0 Parameterizations, 0 Shared Test Fixture Classes, 0 Tags.

Select all the tests with the 'Unit' tag and display their names.

s2 = suite.selectIf(HasTag('Unit'));
{s2.Name}'

33 Unit Testing

Free download pdf