Documentation

Script-Based Unit Tests

Write and run test scripts

Write script-based tests to check that the outputs of MATLAB®scripts, functions, or classes are as you expect. For example, you can use theassertfunction to test for actual output values that match expected values. Or you can test that the output variables have the correct size and type. To run your test scripts use theruntestsfunction.

To get started, seeWrite Script-Based Unit Tests.

For more advanced test authoring, including access to many different types of test qualifications, consider writingFunction-Based Unit TestsorClass-Based Unit Tests.

Functions

assert Throw error if condition false
runtests Run set of tests
testsuite Create suite of tests

Classes

TestResult Result of running test suite

Topics

Write Test Using Live Script

This example shows how to write a live script that tests a function that you create.

Write Script-Based Unit Tests

This example shows how to write a script that tests a function that you create.

Write Script-Based Test Using Local Functions

This example shows how to write a script-based test that uses local functions as helper functions.

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.

Extending Script-Based Tests

Access additional functionality using script-based tests, including test selection, programmatic access of test diagnostics, and test runner customization.

Was this topic helpful?