Run Test Suites by Name
You can run a group, or suite, of tests together. To run the test suite using runtests, the
suite is defined as a cell array of character vectors representing a test file, a test class, a
package that contains tests or a folder that contains tests.
suite = {'axesPropertiesTest','DocPolynomTest'};
runtests(suite);
Run all tests in the current folder using the pwd as input to the runtests function.
runtests(pwd);
Alternatively, you can explicitly create Test arrays and use the run method to run them.
Run Test Suites from Test Array
You can explicitly create Test arrays and use the run method in the TestSuite class to
run them. Using this approach, you explicitly define TestSuite objects and, therefore,
can examine the contents. The runtests function does not return the TestSuite object.
import matlab.unittest.TestSuite
s1 = TestSuite.fromClass(?DocPolynomTest);
s2 = TestSuite.fromFile('axesPropertiesTest.m');
% generate test suite and then run
fullSuite = [s1 s2];
result = run(fullSuite);
Since the suite is explicitly defined, it is easy for you to perform further analysis on the
suite, such as rerunning failed tests.
failedTests = fullSuite([result.Failed]);
result2 = run(failedTests);
Run Tests with Customized Test Runner
You can specialize the test running by defining a custom test runner and adding plugins.
The run method of the TestRunner class operates on a TestSuite object.
import matlab.unittest.TestRunner
import matlab.unittest.TestSuite
Run Tests for Various Workflows