MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

If you use one of the suite creation methods with a selector or name-value pair, the
testing framework creates the filtered suite. If you use the TestSuite.selectIf
method, the testing framework creates a full test suite and then filters it. For large test
suites, this approach can have performance implications.


Test Running


There are several ways to run a function-based test.


To Run All Tests Use Function
In a file runtests with the name of the test file
In a suite TestSuite.run with the suite
In a suite with a custom test
runner

TestRunner.run. (See “Test Runner Customization” on
page 33-46.)

For more information, see “Run Tests for Various Workflows” on page 33-105.


Programmatic Access of Test Diagnostics


If you run tests with the runtests function or the run method of TestSuite or
TestCase, the test framework uses a DiagnosticsRecordingPlugin plugin that
records diagnostics on test results.


After you run tests, you can access recorded diagnostics via the DiagnosticRecord field
in the Details property on TestResult. For example, if your test results are stored in
the variable results, find the recorded diagnostics for the second test in the suite by
invoking records = result(2).Details.DiagnosticRecord.


The recorded diagnostics are DiagnosticRecord objects. To access particular types of
test diagnostics for a particular test, use the selectFailed, selectPassed,
selectIncomplete, and selectLogged methods of the DiagnosticRecord class.


By default, the DiagnosticsRecordingPlugin plugin records qualification failures and
logged events at the matlab.unittest.Verbosity.Terse level of verbosity. For more
information, see DiagnosticsRecordingPlugin and DiagnosticRecord.


Extending Function-Based Tests
Free download pdf