Main Content

createSharedTestFixture

Class: matlab.unittest.plugins.TestRunnerPlugin
Namespace: matlab.unittest.plugins

Extend creation of shared test fixtures

Description

example

f = createSharedTestFixture(plugin,pluginData) extends the creation of shared test fixtures and returns the modified Fixture instance. The testing framework uses the fixture to customize running tests that use shared fixtures. The framework evaluates this method within the scope of the runTestSuite method for each shared test fixture it needs to set up.

A typical implementation of this method is to add listeners to various events originating from the shared test fixture. Because the Fixture class inherits from the handle class, add listeners by calling the addlistener method from within the createSharedTestFixture method.

Input Arguments

expand all

Plugin, specified as a matlab.unittest.plugins.TestRunnerPlugin object.

Shared test fixture creation information, specified as a matlab.unittest.plugins.plugindata.TestContentCreationPluginData object. The testing framework uses this information to describe the test content to the plugin.

Attributes

Accessprotected

To learn about attributes of methods, see Method Attributes.

Examples

expand all

Create a plugin and override the createSharedTestFixture method to count the number of shared test fixture assertion failures.

Add a listener to listen for assertion failures. Use the captureFixtureAssertionFailureData helper method to populate the FixtureAssertionFailureData property.

classdef ExamplePlugin < matlab.unittest.plugins.TestRunnerPlugin
    properties (SetAccess=private)
        FixtureAssertionFailureData = {};
    end

    methods (Access=protected)
        function fixture = createSharedTestFixture(plugin,pluginData)
            % Invoke the super class method
            fixture = createSharedTestFixture@ ...
                matlab.unittest.plugins.TestRunnerPlugin(plugin,pluginData);

            % Get the fixture name
            fixtureName = pluginData.Name;

            % Add a listener to fixture assertion failures
            % and capture the qualification failure information
            fixture.addlistener('AssertionFailed',@(~,evd) ...
                plugin.captureFixtureAssertionFailureData(evd,fixtureName))
        end
    end

    methods (Access=private)
        function captureFixtureAssertionFailureData(plugin,eventData,fixtureName)
            plugin.FixtureAssertionFailureData{end+1} = struct( ...
                'FixtureName',fixtureName, ...
                'ActualValue',eventData.ActualValue, ...
                'Constraint' ,eventData.Constraint, ...
                'Stack'      ,eventData.Stack);
        end
    end
end

Version History

Introduced in R2014a