Extend Unit Testing Framework

Customize testing environment; author constraints, fixtures, diagnostics, and plugins

The MATLAB® Unit Testing Frameworks provides test tool authors the ability to customize the testing environment. You can extend test writing through custom constraints, fixtures, and diagnostics, and extend test running and result reporting through custom plugins for the test runner.

Classes

expand all

matlab.unittest.constraints.ConstraintFundamental interface class for comparisons
matlab.unittest.constraints.BooleanConstraintInterface class for Boolean combinations of constraints
matlab.unittest.constraints.ToleranceAbstract interface class for tolerances
matlab.unittest.fixtures.FixtureInterface class for test fixtures
matlab.unittest.diagnostics.DiagnosticFundamental interface class for matlab.unittest diagnostics
matlab.unittest.diagnostics.ConstraintDiagnosticDiagnostic with fields common to most constraints
matlab.unittest.plugins.TestRunnerPluginPlugin interface for extending TestRunner
matlab.unittest.plugins.ParallelizableInterface for plugins that support running tests in parallel
matlab.unittest.plugins.QualifyingPluginInterface for plugins that perform system-wide qualifications
matlab.unittest.plugins.OutputStreamInterface that determines where to send text output
matlab.test.behavior.MissingTest if class satisfies contract for missing values

Packages

matlab.unittest.plugins.plugindataSummary of classes in MATLAB Plugin Data Interface

Topics

Constraints

Create Custom Constraint

Create a custom constraint to determine if a given value has the same size as an expected value.

Create Custom Boolean Constraint

Create a custom Boolean constraint to determine if a given value has the same size as an expected value.

Create Custom Tolerance

This example shows how to create and apply a custom tolerance.

Fixtures

Create Basic Custom Fixture

This example shows how to create a basic custom fixture.

Create Advanced Custom Fixture

This example shows how to create a custom fixture with a configurable constructor.

Plugins

Write Plugins to Extend TestRunner

Use the TestRunnerPlugin class to extend the TestRunner. You can implement methods to extend the creation, setup, running, and teardown of tests or test fixtures.

Create Custom Plugin

Create a custom plugin that counts the number of passing and failing assertions.

Run Tests in Parallel with Custom Plugin

Create a custom plugin that counts the number of passing and failing assertions when tests run in parallel.

Write Plugin to Save Diagnostic Details

This example shows how to create a custom plugin to save diagnostic details. The plugin listens for test failures and saves diagnostic information so you can access it after the framework completes the tests.

Plugin to Generate Custom Test Output Format

This example shows how to create a plugin that uses a custom format to write finalized test results to an output stream.