Class-Based Unit Tests
Write class-based tests; parameterize tests; apply fixtures; select and run tests
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.
To get started, see Author Class-Based Unit Tests in MATLAB and Write Simple Test Case Using Classes.
|Test Browser||Run MATLAB tests and view results|
|Run set of tests|
|Create suite of tests|
|Create test runner|
|Run test suite|
|Run tests corresponding to test case|
|Run all tests in |
|Superclass of all test classes|
|Fundamental interface for grouping tests to run|
|Specification of a single test|
|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 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|
- Author Class-Based Unit Tests in MATLAB
To test a MATLAB program, write a unit test using qualifications that are methods for testing values and responding to failures.
- Write Simple Test Case Using Classes
Write class-based unit tests to determine the correctness of your program.
- Write Setup and Teardown Code Using Classes
Specify setup and teardown code that runs before and after each
Testmethod or all
Testmethods in a test class.
- Write Tests Using Shared Fixtures
Share fixtures across test classes when creating tests.
- Tag Unit Tests
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.
- Insert Test Code Using Editor
Write a parameterized test interactively by using the options in the MATLAB Editor.
- Table of Verifications, Assertions, and Other Qualifications
Test values and respond to failures using verifications, assumptions, assertions, and fatal assertions.
Write Parameterized Test
- Use Parameters in Class-Based Tests
Use parameters to provide data that should be used iteratively by your tests.
- Create Basic Parameterized Test
Test a function by creating a test that is parameterized in the
- Create Advanced Parameterized Test
Create a test that is parameterized in the
- Define Parameters at Suite Creation Time
TestParameterDefinitionmethod to define parameters at test suite creation time.
- Use External Parameters in Parameterized Test
Use data-driven testing to inject variable inputs into your parameterized test.
Run Tests and Analyze Results
- Create Simple Test Suites
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 Tests for Various Workflows
Explore different ways to run tests.
- Run Tests Using Test Browser
Run your tests interactively by using the test browser.
- 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 as
Incompleteinstead of producing test failures. To avoid test code that is not executed, monitor the filtered tests.
- Programmatically Access Test Diagnostics
Programmatically access the diagnostics that the testing framework records on test results.
- Add Plugin to Test Runner
This example shows how to add a plugin to the test runner.
- Types of Code Coverage for MATLAB Source Code
Use different types of code coverage to analyze your MATLAB source code.
- Collect Statement and Function Coverage Metrics for MATLAB Source Code
Collect and analyze information about statement and function coverage for your MATLAB source code.
- Compile MATLAB Unit Tests
Create a standalone application to run your tests on target machines that do not have MATLAB installed.