matlabtest.parameters.BaselineParameter - Baseline parameter - MATLAB (original) (raw)

Main Content

Namespace: matlabtest.parameters

Baseline parameter

Since R2024b

Description

The matlabtest.parameters.BaselineParameter class represents a specific type of parameter used for baseline testing. To create a baseline test, set a parameterization property in your test class to a BaselineParameter object and then specify that property as an input to a method that tests against the baseline data. For more information, see Create Baseline Tests for MATLAB Code.

A BaselineParameter object contains parameterization information for the test. Similar to creating parameters from a cell array or structure assigned to a parameterization property, the testing framework automatically transforms aBaselineParameter object into the parameter required to run the baseline test. For more information about test parameterization, see Use Parameters in Class-Based Tests.

The matlabtest.parameters.BaselineParameter class is a handle class.

Examples

collapse all

Write a baseline test by using a baseline parameter in a test class.

In your current folder, create a MAT file named testdata.mat that contains the expected output of the magic function when called with5 as its input.

M = magic(5); save("testdata.mat","M")

In a file named ExampleTest.m in your current folder, create theExampleTest test class that compares a value against the baseline data in testdata.mat. The Test method in the class defines a baseline test because it relies on a baseline parameter created using thematlabtest.parameters.matfileBaseline function.

classdef ExampleTest < matlab.unittest.TestCase properties (TestParameter)
baseline = matlabtest.parameters.matfileBaseline("testdata.mat") end

methods (Test)
    function baselineTest(testCase,baseline)
        actual = magic(5);
        testCase.verifyEqualsBaseline(actual,baseline)
    end
end

end

Create a test suite from the ExampleTest class, and display the name of the baseline test.

suite = testsuite("ExampleTest"); disp({suite.Name}')

{'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. The testing framework transformed theBaselineParameter object into the test parameter required to run the baseline test. Note that the value of the test parameter is a matlabtest.baselines.MATFileBaseline object, which the framework passes to the Test method when running the baseline test.

disp(suite(1).Parameterization)

TestParameter with properties:

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

Run the baseline test. The test passes because the actual value is equal to the baseline data in testdata.mat.

result = runtests("ExampleTest");

Running ExampleTest . Done ExampleTest


Version History

Introduced in R2024b