Main Content

retrieveFrom

Class: matlab.unittest.plugins.Parallelizable
Namespace: matlab.unittest.plugins

Retrieve data stored for group of tests

Description

data = retrieveFrom(plugin,buffer) retrieves the data collected using the plugin from the specified communication buffer. The data must be stored in buffer by a MATLAB® worker while running a group of tests.

To run tests in parallel, the testing framework divides the original test suite into groups and assigns them to workers on the current parallel pool (requires Parallel Computing Toolbox™). To enable the MATLAB client to retrieve data from the workers, invoke retrieveFrom within the scope of the reportFinalizedSuite method. The workers must store their data by invoking the storeIn method within the scope of runTestSuite.

example

data = retrieveFrom(plugin,buffer,DefaultData=defaultData) returns the specified default data if buffer is empty in unexpected circumstances, such as when a fatal assertion failure prevents all workers from storing data. If buffer contains data, the method retrieves the stored data as expected. (since R2024a)

Input Arguments

expand all

Plugin, specified as an instance of the plugin class that subclasses the matlab.unittest.plugins.Parallelizable interface.

Buffer from which the client retrieves data, specified as a matlab.unittest.plugins.plugindata.CommunicationBuffer object. buffer represents a property of the FinalizedSuitePluginData instance that is passed to the reportFinalizedSuite method.

Since R2024a

Default data to return if buffer is empty, specified as a value of any data type.

Attributes

Accessprotected
Sealedtrue

To learn about attributes of methods, see Method Attributes.

Examples

expand all

Create a parallelizable plugin that displays the number of running and finalized tests in existing test groups. To retrieve the number of tests in a finalized group, invoke the retrieveFrom method within the scope of the reportFinalizedSuite method.

classdef ExamplePlugin < ...
        matlab.unittest.plugins.TestRunnerPlugin & ...
        matlab.unittest.plugins.Parallelizable
    
    methods (Access = protected)
        function runTestSuite(plugin,pluginData) 
            % Display and store running test suite size
            suiteSize = numel(pluginData.TestSuite);
            fprintf("### Running %d test(s)\n",suiteSize)
            plugin.storeIn(pluginData.CommunicationBuffer,suiteSize);
            
            % Invoke the superclass method
            runTestSuite@ ...
                matlab.unittest.plugins.TestRunnerPlugin(plugin,pluginData)
        end
        
        function reportFinalizedSuite(plugin,pluginData)
            % Retrieve and display finalized test suite size
            suiteSize = plugin.retrieveFrom(pluginData.CommunicationBuffer);
            fprintf("### Finished running %d test(s)\n",suiteSize)

            % Invoke the superclass method
            reportFinalizedSuite@ ...
                matlab.unittest.plugins.TestRunnerPlugin(plugin,pluginData)
        end
    end
end

Version History

Introduced in R2019b

expand all