Extending Script-Based Tests
In this section...
“Test Suite Creation” on page 33-17
“Test Selection” on page 33-18
“Programmatic Access of Test Diagnostics” on page 33-19
“Test Runner Customization” on page 33-19
Typically, with script-based tests, you create a test file, and pass the file name to the
runtests function without explicitly creating a suite of Test objects. If you create an
explicit test suite, there are additional features available in script-based testing. These
features include selecting tests and using plugins to customize the test runner. For
additional functionality, consider using “Function-Based Unit Tests” or “Class-Based Unit
Tests”.
Test Suite Creation
To create a test suite from a script-based test directly, use the testsuite function. For a
more explicit test suite creation, use the fromFile method of TestSuite. Then you can
use the run method instead of the runtests function to run the tests. For example, if
you have a script-based test in a file rightTriTolTest.m, these three approaches are
equivalent.
% Implicit test suite
result = runtests('rightTriTolTest.m');
% Explicit test suite
suite = testsuite('rightTriTolTest.m');
result = run(suite);
% Explicit test suite
suite = matlab.unittest.TestSuite.fromFile('rightTriTolTest.m');
result = run(suite);
Also, you can create a test suite from all the test files in a specified folder using the
TestSuite.fromFolder method. If you know the name of a particular test in your
script-based test file, you can create a test suite from that test using
TestSuite.fromName.
Extending Script-Based Tests