Main Content

matlabtest.selectors.HasBaseline Class

Namespace: matlabtest.selectors

Select TestSuite array elements by baseline-specific parameterization

Since R2024b

Description

The matlabtest.selectors.HasBaseline class provides a selector for filtering a test suite based on baseline-specific parameterization. Use the selector to create either a test suite that contains only baseline tests or a test suite that does not contain baseline tests. For more information about baseline tests, see Create Baseline Tests for MATLAB Code.

Creation

Description

selector = matlabtest.selectors.HasBaseline creates a selector that selects TestSuite array elements that include one or more baseline parameters. For more information about baseline parameters, see matlabtest.parameters.BaselineParameter.

example

Examples

collapse all

Create filtered test suites by selecting tests using the HasBaseline class.

In a file named ExampleTest.m in your current folder, create the ExampleTest class, which tests the magic function. The class has two parameterized Test methods: sizeTest and baselineTest. Of the parameterized methods, the baselineTest method defines a baseline test because it relies on a baseline parameter created using the matlabtest.parameters.matfileBaseline function.

classdef ExampleTest < matlab.unittest.TestCase
    properties (TestParameter)
        order = {3,5,10}
        baseline = matlabtest.parameters.matfileBaseline("testdata.mat")
    end

    methods (Test)
        function classTest(testCase)
            testCase.verifyClass(magic(5),"double")
        end

        function sizeTest(testCase,order)
            testCase.verifySize(magic(order),[order order])
        end

        function baselineTest(testCase,baseline)
            verifyEqualsBaseline(testCase,magic(5),baseline)
        end
    end
end

Import the classes used in this example.

import matlab.unittest.selectors.HasParameter
import matlabtest.selectors.HasBaseline

Create a test suite from the ExampleTest class and display the test names. The suite contains five Test elements.

suite = testsuite("ExampleTest");
disp({suite.Name}')
    {'ExampleTest/classTest'                                }
    {'ExampleTest/sizeTest(order=3)'                        }
    {'ExampleTest/sizeTest(order=5)'                        }
    {'ExampleTest/sizeTest(order=10)'                       }
    {'ExampleTest/baselineTest(baseline=testdata.mat(data))'}

Display the parameterization data required to run the baseline test by returning the value of the Parameterization property of the corresponding matlab.unittest.Test element.

disp(suite(5).Parameterization)
  TestParameter with properties:

    Property: 'baseline'
        Name: 'testdata.mat(data)'
       Value: [1×1 matlabtest.baselines.MATFileBaseline]

Now, create a filtered test suite by selecting the parameterized tests. The filtered test suite contains the four parameterized tests, including the baseline test.

suite1 = suite.selectIf(HasParameter);
disp({suite1.Name}')
    {'ExampleTest/sizeTest(order=3)'                        }
    {'ExampleTest/sizeTest(order=5)'                        }
    {'ExampleTest/sizeTest(order=10)'                       }
    {'ExampleTest/baselineTest(baseline=testdata.mat(data))'}

Select only the baseline test by using the HasBaseline class instead of the HasParameter class.

suite2 = suite.selectIf(HasBaseline);
disp({suite2.Name}')
    {'ExampleTest/baselineTest(baseline=testdata.mat(data))'}

Create a filtered test suite by excluding baseline tests from the original test suite.

suite3 = suite.selectIf(~HasBaseline);
disp({suite3.Name}')
    {'ExampleTest/classTest'         }
    {'ExampleTest/sizeTest(order=3)' }
    {'ExampleTest/sizeTest(order=5)' }
    {'ExampleTest/sizeTest(order=10)'}

Version History

Introduced in R2024b