Write xUnit-style tests to check that the output of MATLAB® code is as you expect. Class-based unit tests give you access to the full unit testing framework functionality. For example, you can write parameterized tests, tag your tests, or use shared test fixtures.
|Superclass of all |
|Class for grouping tests to run|
|Specification of single test method|
|Class for running tests in |
|Result of running test suite|
|Summary of packages and classes in MATLAB Unit Test Framework|
|Summary of classes in MATLAB Qualifications Interface|
|Summary of classes in MATLAB Constraints Interface|
|Summary of classes in MATLAB Diagnostics Interface|
|Summary of classes in MATLAB Fixtures Interface|
|Summary of classes associated with MATLAB Unit Test parameters|
|Summary of classes in MATLAB Plugins Interface|
|Summary of classes in MATLAB Selectors Interface|
|Constraint that compares time series data with tolerances using the Simulation Data Inspector|
To test a MATLAB program, write a unit test using qualifications that are methods for testing values and responding to failures.
Test values and respond to failures using verifications, assumptions, assertions, and fatal assertions.
This example shows how to write a class-based unit test.
Setup and teardown code, or test fixtures, sets up the pretest state of the system and returns it to the original state after running the test. You can define setup and teardown methods that run before and after each test method or all test methods in a test class.
Use test tags to group tests into categories and then run tests with specified tags. Typical test tags identify a particular feature or describe the type of test.
You can share test fixtures across test classes. This example shows how to use shared fixtures when creating tests.
This example shows how to create a basic parameterized test.
This example shows how to create a test that is parameterized in the
Use data-driven testing to inject variable inputs into your parameterized test.
This example shows how to combine tests into test suites, whether they are organized in packages and classes or files and folders, or both.
Run your tests while working in the Editor or Live Editor.
Explore different ways to run tests.
If you run tests with the
runtests function or the
run method of
TestCase, the test framework uses a
DiagnosticsRecordingPlugin plugin that records diagnostics on test results.
This example shows how to add a plugin to the test runner.
This example shows how to analyze the information returned by a test runner.
This example shows how to identify and handle failed tests.
Rerun failed tests quickly and conveniently.
Assumption failures produce filtered tests that are marked as
Incomplete instead of producing test failures. To avoid test code that is not executed, monitor the filtered tests.