Main Content

Function-Based Unit Tests

Write tests using qualifications; customize test runner; select and run tests

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.

To get started, see Write Function-Based Unit Tests and Write Simple Test Case Using Functions.

For more advanced test authoring, including using test parameterization and test fixtures, consider writing Class-Based Unit Tests.

Apps

Test BrowserRun MATLAB tests and view results (Since R2023a)

Functions

functiontestsCreate array of tests from handles to local functions
runtestsRun set of tests
testsuiteCreate suite of tests
testrunnerCreate test runner (Since R2021a)
run (TestSuite)Run test suite using default test runner

Classes

TestSpecification of a single test
FunctionTestCaseTestCase used for function-based tests
TestResultResult of running test suite

Topics

Write Tests

Run Tests and Analyze Results