MATLAB® xUnit Test Framework

MATLAB xUnit is a unit test framework for MATLAB code. MATLAB xUnit is designed to be easy to use for MATLAB users with a wide range of experience. Users can write tests using ordinary M-files that are very simple in structure.

Important Note: MATLAB xUnit relies heavily on object-oriented language features introduced in MATLAB 7.6 (R2008a), which was released in March 2008. MATLAB xUnit functions and classes will not work in earlier MATLAB releases. In addition, writing and running tests inside packages requires MATLAB 7.7 (R008b) or later.

Installation

To use MATLAB xUnit in MATLAB, add the "xunit" folder (directory) to the MATLAB path. See the MATLAB documentation for setting the search path. (The "tests" directory contains the framework's own self-tests, and the "architecture" directory contains information about the framework architecture; these directories are not needed for using MATLAB xUnit.)

Note for users of earlier versions of MATLAB xUnit: If you have already written unit tests based on MTEST, an earlier version of MATLAB xUnit, you may also want to add the "obsolete" folder to the MATLAB path. This folder contains the old command-line test runner, mtest, as well as the deprecated function assertAlmostEqual.

Getting Started

Quick Start: How to Write and Run Tests

How to Put Multiple Test Cases in One M-file

How to Run a Specific Test

How to Run Tests in Specific Directories

How to Run Tests in a Package

Advanced Usage

How to Test Using a Floating-Point Tolerance

How to Test an Error Message

How to Run Tests Silently and Query the Results

How to Write Tests That Share Common Set-Up Code

How to Write xUnit-Style Tests by Subclassing TestCase

How MATLAB xUnit Searches for Test Cases

Key Functions and Classes

Main test driver function:

Assertion functions you can use in your tests:

The key xUnit-style classes that make everything work:

Release History

Copyright 2008-2010 The MathWorks, Inc.