Write function-based tests to check that the outputs of MATLAB® scripts, functions, or classes are as you expect. You can use a full library of qualification functions to produce four different types of test failures. For example, you can produce verification or fatal assertion test failures. Function-based tests subscribe to the xUnit testing philosophy.
For more advanced test authoring, including using test parameterization and test fixtures, consider writing Class-Based Unit Tests.
Your test function is a single MATLAB file that contains a main function and your individual local test functions. Optionally, you can include file fixture and fresh fixture functions.
This example shows how to write and run a function-based unit test.
This example shows how to write a function-based test with setup and teardown functions that run once in your test file and before and after each test function in the file.
Test values and respond to failures using verifications, assumptions, assertions, and fatal assertions.
This example shows how to run a test, while working in the Editor.
Explore different ways to run tests.
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.
Access additional functionality using function-based tests, including application of fixtures, test selection, programmatic access of test diagnostics, and test runner customization.