Main Content

Extend MATLAB Unit Testing Framework with MATLAB Test

MATLAB® Test™ extends the functionality 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.

  • 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 "n-wise" parameter combination.

This topic provides a summary of how MATLAB Test extends the functionality provided by existing MATLAB apps, functions, and classes. 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 MATLAB Test installed, you can use CodeCoveragePlugin and Test Browser to also measure the decision coverage, condition coverage, and MC/DC of your source code.

Filter Test Suite by Source Code Dependency

If you have MATLAB Test installed, 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:

Create and Run Suite of Tests That Verify Requirements

If you have MATLAB Test and Requirements Toolbox installed, 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 also can 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

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 n-tuple of parameter values. To use this type of parameter combination, specify the ParameterCombination attribute of the method as "n-wise", where n is an integer between 2 and 10. The "n-wise" parameter combination generalizes the "pairwise" combination.

See Also




Related Topics