# 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.

## 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

## 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:

- `runtests`

Assertion functions you can use in your tests:

- `assertTrue`
- `assertFalse`
- `assertEqual`
- `assertFilesEqual`
- `assertElementsAlmostEqual`
- `assertVectorsAlmostEqual`
- `assertExceptionThrown`

The key xUnit-style classes that make everything work:

- `TestComponent`
- `TestSuite`
- `TestCase`
- `FunctionHandleTestCase`
- `TestRunMonitor`
- `TestRunLogger`
- `CommandWindowTestRunDisplay`

Release History

Copyright 2008-2009 The MathWorks, Inc.