本页对应的英文页面已更新,但尚未翻译。 若要查看最新内容,请点击此处访问英文页面。

runInParallel

类: matlab.unittest.TestRunner
包: matlab.unittest

并行运行 TestSuite 数组中的所有测试

说明

示例

result = runInParallel(runner,suite) 并行运行 TestSuite 数组中的所有测试,并返回 TestResult 对象形式的结果。runInParallel 方法将 suite 分为几个不同的组,并使用 runner 在当前并行池内运行每个组。

注意

runInParallel 方法需要 Parallel Computing Toolbox™。测试框架可能会改变组的顺序和数量,或每个组中所包含的测试。

选择要并行运行的测试套件时,请考虑可能的资源争用。例如,如果您的测试脚手架要访问全局资源(例如同一网络上的共享文件),并行会话可能会相互冲突。在这种情况下,可考虑使用预置的共享测试脚手架。

输入参数

全部展开

并行测试组的测试运行程序,指定为 matlab.unittest.TestRunner 实例。

并行运行测试前,请先考虑测试运行程序配置。由于 runInParallel 方法在不同的工作进程上运行不同的测试组,有些插件(例如 StopOnFailuresPlugin)并不适合并行处理。测试框架支持使用自定义插件并行运行测试,前提是该插件会子类化 Parallelizable 接口。

要并行运行的测试集合,指定为 matlab.unittest.Test 数组。

示例

全部展开

在您的当前工作文件夹下的文件中,创建以下参数化测试。

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 logarithmicly spaced sizes up to 100
sizes = num2cell(round(logspace(0,2,10)));
end

在命令提示符下,基于 TestRand.m 创建一个套件和一个会在命令行窗口中显示文本的测试运行程序。

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

套件包含 1200 个测试元素。

并行运行测试套件。

result = 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
__________



result = 

  1200x1 TestResult array with properties:

    Name
    Passed
    Failed
    Incomplete
    Duration
    Details

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

在 R2015a 中推出