This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

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 the assert function 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 the runtests function.

To get started, see Write Script-Based Unit Tests.

For more advanced test authoring, including access to many different types of test qualifications, consider writing Function-Based Unit Tests or Class-Based Unit Tests.


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


TestResult Result of running test suite


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 rerun failed tests.

Additional Topics for 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?