This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

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.

Functions

functiontestsCreate array of tests from handles to local functions
runtestsRun set of tests
testsuiteCreate suite of tests
TestSuite.runRun TestSuite array using TestRunner object configured for text output

Classes

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

Topics

Write Tests

Write Function-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.

Types of Qualifications

Qualifications are functions for testing values and responding to failures. This summary describes the four types of qualifications and qualification functions that are available in the MATLAB unit testing framework.

Write Simple Test Case Using Functions

This example shows how to write and run a function-based unit test.

Write Test Using Setup and Teardown Functions

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.

Types of Qualifications

Qualifications are functions for testing values and responding to failures. This summary describes the four types of qualifications and qualification functions that are available in the MATLAB unit testing framework.

Run Tests and Analyze Results

Run Tests in Editor

This example shows how to run a test, while working in the Editor.

Run Tests for Various Workflows

Explore different ways to run tests.

Analyze Test Case Results

This example shows how to analyze the information returned by a test runner.

Analyze Failed Test Results

This example shows how to 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 as Incomplete instead of producing test failures. To avoid test code that is not executed, monitor the filtered tests.

Extending Function-Based Tests

Access additional functionality using function-based tests, including application of fixtures, test selection, programmatic access of test diagnostics, and test runner customization.