Extend MATLAB Unit Testing Framework with MATLAB Test
MATLAB® Test™ extends the capabilities of the MATLAB unit testing framework. For example, with MATLAB Test, you can:
Measure the decision coverage, condition coverage, and modified condition/decision coverage (MC/DC) of your source code.
Generate a standalone code coverage report.
Filter a test suite by source code dependency.
Create and run a suite of tests that verify requirements (requires Requirements Toolbox™).
Run tests by using the
"
parameter combination.n
-wise"
This topic provides a summary of how MATLAB Test extends the functionality provided by existing MATLAB apps, classes, and functions. For more information about the MATLAB unit testing framework, see Ways to Write Unit Tests.
Measure Decision Coverage, Condition Coverage, and MC/DC
The unit testing framework lets you measure the statement coverage and function
coverage of your MATLAB source code. You can collect and access these metrics either
programmatically by using the matlab.unittest.plugins.CodeCoveragePlugin
class or interactively by using the Test Browser
app. If you have a MATLAB
Test license, you can use CodeCoveragePlugin
and Test
Browser to also measure the decision coverage, condition coverage, and MC/DC
of your source code.
Generate Standalone Code Coverage Report
Since R2024a
If you have a MATLAB
Test license, you can generate a standalone code coverage report as a single
file by using the generateStandaloneReport
method of the matlab.coverage.Result
class. Alternatively, you can generate a standalone
report if you create a CodeCoveragePlugin
instance using the matlabtest.plugins.codecoverage.StandaloneReport
class.
Filter Test Suite by Source Code Dependency
If you have a MATLAB
Test license, you can filter a test suite by test file dependency on specified
source code. To specify the source files and folders, use the matlabtest.selectors.DependsOn
class or the DependsOn
name-value argument. You can specify the DependsOn
name-value
argument for these methods and functions of the unit testing framework:
Static methods of the
matlab.unittest.TestSuite
class, such asmatlab.unittest.TestSuite.fromFolder
Create and Run Suite of Tests That Verify Requirements
If you have MATLAB
Test and Requirements Toolbox licenses, you can create a test suite from tests that verify requirements
by using matlab.unittest.TestSuite.fromRequirements
, which is a static method of
the matlab.unittest.TestSuite
class. You can also use the
testsuite
and runtests
functions to
respectively create a suite of tests and run tests that verify requirement sets.
Run Tests Using "n
-wise"
Parameter Combination
n
-wise"When you pass more than one parameterization property to a method of a matlab.unittest.TestCase
subclass,
MATLAB
Test can invoke the method for every
-tuple of parameter values. To use
this type of parameter combination, specify the n
ParameterCombination
attribute of the method as "
, where
n
-wise"
is an integer between 2 and 10.
The n
"
parameter combination
generalizes the n
-wise""pairwise"
combination.
See Also
Apps
Functions
Classes
matlab.unittest.TestCase
|matlab.unittest.TestSuite
|matlab.unittest.plugins.CodeCoveragePlugin
|matlab.coverage.Result