Main Content

run

Class: matlab.unittest.TestSuite
Namespace: matlab.unittest

Run test suite using default test runner

Description

results = run(suite) runs the test suite using a default test runner, which is similar to the runner that the testing framework configures by default when you call the runtests function. The method returns the results of the test run as a matlab.unittest.TestResult array, where each TestResult object corresponds to an element of suite.

example

Input Arguments

expand all

Test suite, specified as a matlab.unittest.TestSuite array.

Attributes

Sealedtrue

To learn about attributes of methods, see Method Attributes.

Examples

expand all

Create a test suite from a test class, and then run the test suite.

In a file named ZerosTest.m in your current folder, create a class-based test to test the zeros function.

classdef ZerosTest < matlab.unittest.TestCase
    properties (TestParameter)
        type = {'single','double','uint16'};
        size = struct("s2d",[3 3],"s3d",[2 5 4]);
    end
    
    methods (Test)
        function testClass(testCase,size,type)
            testCase.verifyClass(zeros(size,type),type)
        end
        
        function testSize(testCase,size)
            testCase.verifySize(zeros(size),size)
        end
        
        function testDefaultClass(testCase)
            testCase.verifyClass(zeros,"double")
        end
        
        function testDefaultSize(testCase)
            testCase.verifySize(zeros,[1 1])
        end
        
        function testDefaultValue(testCase)
            testCase.verifyEqual(zeros,0)
        end
    end
end

Create a test suite from the ZerosTest test class.

suite = testsuite("ZerosTest");

Run the test suite. All the tests pass.

results = run(suite);
Running ZerosTest
.......... .
Done ZerosTest
__________

Tips

  • run is a convenience method. For example, results = run(suite) is functionally equivalent to the following code.

    runner = testrunner;
    results = run(runner,suite)

Version History

Introduced in R2013a