matlab.unittest.TestRunner.runInParallel - Run all tests in test suite in parallel - MATLAB (original) (raw)

Class: matlab.unittest.TestRunner
Namespace: matlab.unittest

Run all tests in test suite in parallel

Syntax

Description

results = runInParallel([runner](#bun586m-runner),[suite](#bun586m-suite)) divides the specified test suite into groups and uses the specified test runner to run each group on the parallel pool returned by the gcp (Parallel Computing Toolbox) function. The method returns the results as an array of TestResult objects.

When tests run in parallel (requires Parallel Computing Toolbox™), test suite portions run independently on MATLAB® workers. For example, if your test class has aTestClassSetup method, the method runs locally on each worker. Workers use the information in their corresponding Test elements to run the tests. Each Test element provides the worker with all the information required to run a test.

Note

The testing framework might vary the order and number of groups or which tests it includes in each group.

example

Input Arguments

expand all

Test runner for parallel test groups, specified as a matlab.unittest.TestRunner instance.

Consider your test runner configuration before running tests in parallel. Since therunInParallel method runs separate groups of tests on different workers, some plugins, such asStopOnFailuresPlugin, are not well suited for parallelization. The testing framework supports running tests in parallel with a custom plugin, provided that the plugin subclasses the Parallelizable interface.

Set of tests to run in parallel, specified as a matlab.unittest.Test array.

Examples

expand all

Create the following parameterized test in a file in your current working folder.

classdef TestRand < matlab.unittest.TestCase
properties (TestParameter) dim1 = createDimensionSizes; dim2 = createDimensionSizes; dim3 = createDimensionSizes; type = {'single','double'}; end

methods (Test)
    function testRepeatable(testCase,dim1,dim2,dim3)
        state = rng;
        firstRun = rand(dim1,dim2,dim3);
        rng(state)
        secondRun = rand(dim1,dim2,dim3);
        testCase.verifyEqual(firstRun,secondRun);
    end
    function testClass(testCase,dim1,dim2,type)
        testCase.verifyClass(rand(dim1,dim2,type),type)
    end
end

end

function sizes = createDimensionSizes % Create logarithmically spaced sizes up to 100 sizes = num2cell(round(logspace(0,2,10))); end

At the command prompt, create a suite from TestRand.m and a test runner that displays text in the Command Window.

suite = matlab.unittest.TestSuite.fromClass(?TestRand); runner = matlab.unittest.TestRunner.withTextOutput();

The suite contains 1200 test elements. Run the tests in parallel.

results = runInParallel(runner,suite)

Split tests into 12 groups and running them on 4 workers.

Finished Group 2

Running TestRand .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... ......... Done TestRand



Finished Group 4

Running TestRand .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... ..... Done TestRand



Finished Group 3

Running TestRand .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... ....... Done TestRand



Finished Group 1

Running TestRand .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .. Done TestRand



Finished Group 7

Running TestRand .......... .......... .......... .......... .......... .......... .......... .......... .......... ......... Done TestRand



Finished Group 5

Running TestRand .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... ... Done TestRand



Finished Group 6

Running TestRand .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... . Done TestRand



Finished Group 8

Running TestRand .......... .......... .......... .......... .......... .......... .......... .......... .......... ....... Done TestRand



Finished Group 11

Running TestRand .......... .......... .......... .......... .......... .......... .......... .......... .......... . Done TestRand



Finished Group 12

Running TestRand .......... .......... .......... .......... .......... .......... .......... .......... ........ Done TestRand



Finished Group 10

Running TestRand .......... .......... .......... .......... .......... .......... .......... .......... .......... ... Done TestRand



Finished Group 9

Running TestRand .......... .......... .......... .......... .......... .......... .......... .......... .......... ..... Done TestRand


results =

1200x1 TestResult array with properties:

Name
Passed
Failed
Incomplete
Duration
Details

Totals: 1200 Passed, 0 Failed, 0 Incomplete. 11.4023 seconds testing time.

Tips

Version History

Introduced in R2015a

expand all

You can run tests on a thread-based pool (requires Parallel Computing Toolbox) by starting a parallel pool of thread workers and then calling therunInParallel method.

Tests to run with runInParallel on a thread-based pool are subject to these restrictions:

You can use runInParallel to run tests in parallel on clusters and clouds (requires MATLAB Parallel Server and Parallel Computing Toolbox).

You can create standalone applications that support running tests in parallel (requires MATLAB Compiler™ and Parallel Computing Toolbox). Use the directive %#function parallel.Pool in your code so that MATLAB Compiler can locate and package all of the components required for running tests in parallel. For more information, see Compile MATLAB Unit Tests.