Run Unit Tests
Select and run tests; customize the test runner; analyze test and coverage
results
Run your tests interactively in the MATLAB® Editor or Live Editor, or in the Test Browser app, or
run your tests programmatically, for example, with the runtests
function or the run
method of the
matlab.unittest.TestSuite
class. Customize your test run with
options, such as running tests in parallel (requires Parallel Computing Toolbox™) or specifying a level of test output detail. Collect code
coverage metrics as you run your tests, and analyze the test and coverage
results.
Apps
Test Browser | Run MATLAB tests and view results (Since R2023a) |
Functions
runtests | Run set of tests |
testsuite | Create suite of tests |
testrunner | Create test runner (Since R2021a) |
run (TestSuite) | Run test suite using default test runner |
run (TestRunner) | Run test suite |
run (TestCase) | Run tests corresponding to test case |
runInParallel | Run all tests in test suite in parallel |
Classes
matlab.unittest.TestCase | Superclass of all test classes |
matlab.unittest.TestSuite | Fundamental interface for grouping tests to run |
matlab.unittest.Test | Specification of a single test |
matlab.unittest.TestRunner | Class for running tests in unit testing framework |
matlab.unittest.TestResult | Result of running test suite |
matlab.coverage.Result | Result of code coverage analysis (Since R2023a) |
Namespaces
matlab.unittest | Summary of classes and namespaces in MATLAB unit testing framework |
matlab.unittest.plugins | Summary of classes in MATLAB plugins interface |
matlab.unittest.selectors | Summary of classes in MATLAB selectors interface |
Topics
Run Tests
- Create Simple Test Suites
Combine tests into test suites, whether they are organized in namespaces and classes or files and folders, or both. - Run Tests for Various Workflows
Explore different ways to run tests. - Run Tests Using Test Browser
Run your tests interactively by using the test browser. (Since R2023a) - Run Tests in Editor
Run your tests while working in the Editor or Live Editor. - Add Plugin to Test Runner
Add a plugin to the test runner. - Compile MATLAB Unit Tests
Create a standalone application to run your tests on target machines that do not have MATLAB installed.
Analyze Results
- Analyze Test Case Results
Analyze the information that a test runner returns. - Analyze Failed Test Results
Identify and handle failed tests. - Rerun Failed Tests
Rerun failed tests quickly and conveniently. - Dynamically Filtered Tests
Assumption failures produce filtered tests that are marked asIncomplete
instead of producing test failures. Monitor the filtered tests for test code that the testing framework does not execute. - Programmatically Access Test Diagnostics
Programmatically access the diagnostics that the testing framework records on test results. - Types of Code Coverage for MATLAB Source Code
Use different types of code coverage to analyze your MATLAB source code. - Collect Statement and Function Coverage Metrics for MATLAB Source Code
Collect and analyze information about statement and function coverage for your MATLAB source code.