Main Content

run

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

Run test suite

Description

results = run(runner,suite) runs the TestSuite array suite using the specified test runner and returns the results of the test run. When running the test suite, the method automatically exercises any setup and teardown code required by the tests.

example

Input Arguments

expand all

Test runner, specified as a matlab.unittest.TestRunner object.

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

Output Arguments

expand all

Results of running the test suite, returned as a matlab.unittest.TestResult array. Elements of results correspond to the elements of suite.

Examples

expand all

Run a suite of tests with a test runner that is configured for text output.

Create a function-based test sampleTest.m in your current folder.

function tests = sampleTest
tests = functiontests(localfunctions);
end

function testA(testCase)      % Test passes
verifyEqual(testCase,2+3,5)
end

function testB(testCase)      % Test fails
verifyGreaterThan(testCase,13,42)
end

function testC(testCase)      % Test passes
verifySubstring(testCase,"Hello world!","llo")
end

Create a test suite from the tests in sampleTest.m.

suite = testsuite("sampleTest.m");

Create a test runner that produces text output and use it to run the tests. The text output includes test run progress as well as diagnostics in the event of test failures.

runner = testrunner("textoutput");
results = run(runner,suite);
Running sampleTest
.
================================================================================
Verification failed in sampleTest/testB.
    ---------------------
    Framework Diagnostic:
    ---------------------
    verifyGreaterThan failed.
    --> The value must be greater than the minimum value.
    
    Actual Value:
        13
    Minimum Value (Exclusive):
        42
    ------------------
    Stack Information:
    ------------------
    In C:\work\sampleTest.m (testB) at 10
================================================================================
..
Done sampleTest
__________

Failure Summary:

     Name              Failed  Incomplete  Reason(s)
    ===============================================================
     sampleTest/testB    X                 Failed by verification.

Display the results from the failing test.

disp(results([results.Failed]))
  TestResult with properties:

          Name: 'sampleTest/testB'
        Passed: 0
        Failed: 1
    Incomplete: 0
      Duration: 1.2982
       Details: [1×1 struct]

Totals:
   0 Passed, 1 Failed (rerun), 0 Incomplete.
   1.2982 seconds testing time.

Version History

Introduced in R2013a