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, seeWrite Function-Based Unit TestsandWrite Simple Test Case Using Functions.
For more advanced test authoring, including using test parameterization and test fixtures, consider writingClass-Based Unit Tests.
Functions
functiontests |
创建数组处理本地功能的测试ons |
runtests |
Run set of tests |
testsuite |
Create suite of tests |
testrunner |
Create test runner |
run (TestSuite) |
RunTestSuite array usingTestRunner object configured for text output |
Classes
Test |
Specification of single test method |
FunctionTestCase |
TestCase used for function-based tests |
TestResult |
Result 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. - Write Simple Test Case Using Functions
Write function-based unit tests to determine the correctness of your program. - Write Test Using Setup and Teardown Functions
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. - Table of Verifications, Assertions, and Other Qualifications
Test values and respond to failures using verifications, assumptions, assertions, and fatal assertions.
Run Tests and Analyze Results
- Run Tests for Various Workflows
Explore different ways to run tests. - Run Tests in Editor
Run your tests while working in the Editor or Live Editor. - 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 asIncomplete
instead of producing test failures. To avoid test code that is not executed, monitor the filtered tests. - Extend 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.