Main Content

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.

Apps

Test BrowserRun MATLAB tests and view results (Since R2023a)

Functions

runtestsRun set of tests
testsuiteCreate suite of tests
testrunnerCreate test runner (Since R2021a)
run (TestSuite)Run test suite using default test runner
run (TestRunner)Run test suite
run (TestCase)Run tests corresponding to test case
runInParallelRun all tests in TestSuite array in parallel

Classes

matlab.unittest.TestCaseSuperclass of all test classes
matlab.unittest.TestSuiteFundamental interface for grouping tests to run
matlab.unittest.TestSpecification of a single test
matlab.unittest.TestRunnerClass for running tests in matlab.unittest framework
matlab.unittest.TestResultResult of running test suite

Packages

matlab.unittestSummary of packages and classes in MATLAB Unit Test Framework
matlab.unittest.qualificationsSummary of classes in MATLAB Qualifications Interface
matlab.unittest.constraintsSummary of classes in MATLAB Constraints Interface
matlab.unittest.fixturesSummary of classes in MATLAB Fixtures Interface
matlab.unittest.parametersSummary of classes associated with MATLAB Unit Test parameters
matlab.unittest.pluginsSummary of classes in MATLAB Plugins Interface
matlab.unittest.selectorsSummary of classes in MATLAB Selectors Interface
Simulink.sdi.constraints.MatchesSignalConstraint that compares time series data with tolerances using the Simulation Data Inspector (Since R2019a)

Topics

Write Tests

Write Parameterized Test

Run Tests and Analyze Results