Ways to Write Unit Tests - MATLAB & Simulink (original) (raw)

Main Content

To guide software development and monitor for regressions in code functionality, you can write unit tests for your programs. The MATLAB® unit testing framework supports three test authoring schemes:

Test authoring schemes in order of increasing functionality: script-based tests, function-based tests, and class-based tests

Script-Based Unit Tests

With script-based tests, you can:

Typically, with script-based tests, you create a test file, and pass the file name to the runtests function without explicitly creating a suite of Test elements. If you create an explicit test suite (using the testsuite function or a method of thematlab.unittest.TestSuite class), there are additional features available in script-based testing. With an explicit test suite, you can:

For more information about script-based tests, see Write Script-Based Unit Tests and Extend Script-Based Tests.

Function-Based Unit Tests

Function-based tests support the functionality provided by script-based tests. In addition, with function-based tests, you can:

For more information about function-based tests, see Function-Based Unit Tests and Extend Function-Based Tests.

Class-Based Unit Tests

Class-based tests support the functionality provided by script-based and function-based tests. In addition, with class-based tests, you can:

For more information about class-based tests, see Class-Based Unit Tests.

Extend Unit Testing Framework

The unit testing framework provides test tool authors the ability to extend test writing through custom constraints, diagnostics, fixtures, and plugins. For example, you can create a custom plugin and use it to extend the test runner when you run your script-based, function-based, or class-based unit tests. For more information, see Extend Testing Frameworks.

See Also

Topics

External Websites