MATLAB Unit Test / MATLAB 单元测试

Classes, How-tos and Examples.

Update History

R2013a

First introduced

  • matlab.unittest package, an xUnit-style testing framework for the MATLAB language that allows writing and running unit tests, and analyzing test results

    New MATLAB Unit Testing Framework (9 min, 24 sec)

    For information about the matlab.unittest package, see Unit Testing Framework.

R2013b

Updated

  • Functions for writing, executing, and verifying tests using the matlab.unittest testing framework without creating custom classes

    As an alternative to writing object-oriented tests, the MATLAB xUnit-style testing framework now provides function-based writing, execution, and verification of tests. For more information, see Unit Testing Framework. For an example of function–based test writing, see Write Simple Test Case Using Functions.

  • New fixture and plugin features for matlab.unittest testing framework

    The matlab.unittest testing framework now provides four customized fixtures to ease the creation of setup and teardown code. You can use these fixtures to change the current working folder, add a folder to the MATLAB path, suppress the display of warnings, and create a temporary folder. For more information, see matlab.unittest.fixtures.

    To share these fixtures across test classes, use the new SharedTestFixtures class attribute of TestCase. The getSharedTestFixtures method of TestCase provides access to the shared fixtures. You also can use fixtures within a test function by calling the applyFixture method of TestCase.

    To pause execution of a test and enter debug mode upon a failure or uncaught error, you can add the new plugin, StopOnFailuresPlugin to the test runner. For more information, see matlab.unittest.plugins.

R2014a

Improved

  • Custom plugins in unit testing framework

    The matlab.unittest testing framework provides an interface class, matlab.unittest.plugins.TestRunnerPlugin, to create custom plugins and extend the TestRunner. For more information, see Write Plugins to Extend TestRunner and Create Custom Plugin.

  • Test parameterization and selection in unit testing framework

    Test authors can write tests that are parameterized to combine and execute over lists of data. For more information, see Create Basic Parameterized Test and Create Advanced Parameterized Test.

    The matlab.unittest.TestSuite.selectIf method, combined with classes in the matlab.unittest.selectors package, allows for the improved selection of tests included in the test suite.

  • matlab.unittest plugin for Test Anything Protocol (TAP) output

    The matlab.unittest testing framework provides a plugin that produces a Test Anything Protocol (TAP) stream. This plugin allows integration of MATLAB unit test results into third-party systems that recognize the Test Anything Protocol such as continuous integration systems. For more information, see the matlab.unittest.plugins.TAPPlugin documentation.

  • Output stream direction for matlab.unittest plugins

    The matlab.unittest testing framework provides a means to redirect text output from several plugins to standard output (ToStandardOutput) or to a file (ToFile). Output stream direction is supported for the DiagnosticsValidationPlugin, FailureDiagnosticsPlugin, TAPPlugin, and TestSuiteProgressPlugin plugins.

    Additionally, the OutputStream class provides an interface for test authors to create custom output streams.

  • Comparator for MATLAB objects in unit testing framework

    The PublicPropertyComparator can be used with the IsEqualTo constraint to compare public properties of MATLAB objects recursively.

  • isdiag, isbanded, issymmetric, ishermitian, istril, istriu, and bandwidth functions for testing matrix structure

    The following functions test various aspects of matrix structure and are useful in simplifying numerical algorithms.

    • ishermitian determines if a matrix is Hermitian or skew-Hermitian.
    • issymmetric determines if a matrix is symmetric or skew-symmetric.
    • istriu determines if a matrix is upper-triangular.
    • istril determines if a matrix is lower-triangular.
    • isdiag determines if a matrix is diagonal.
    • bandwidth returns the upper and lower bandwidth of a matrix.
    • isbanded determines if a matrix is within the specified upper and lower bandwidths.

Unit Testing Framework 单元测试框架

Write and run tests for MATLAB® programs
为MATLAB程序编写和运行测试

  • Write Unit Tests 编写单元测试
    Assemble test methods into test-case classes
    将各个测试方法组合成测试用例类

  • Run Unit Tests 运行单元测试
    Run test suites in the testing framework
    在测试框架中运行测试用例集

  • Analyze Test Results 分析测试结果
    Use test results to identify failures
    使用测试结果来分析程序

Write Unit Tests 编写单元测试

Assemble test methods into test-case classes
将各个测试方法组合成测试用例类

The matlab.unittest package is an xUnit-style, unit-testing framework for MATLAB®. To test a MATLAB program, write a test case using qualifications, which are methods for testing values and responding to failures. The test case contains test functions and test fixtures (setup and teardown code).
matlab.unittest包是xUnit风格的matlab程序测试框架。

Functions 函数

  • functiontests
    • Create array of tests from handles to local functions
    • 使用局部函数指针生成测试组

Classes 类

Packages 包

  • matlab.unittest
    • Summary of packages and classes in MATLAB Unit Test Framework
    • MATLAB 单元测试框架类函数包和函数类的集合
  • matlab.unittest.constraints
    • Summary of classes in MATLAB Constraints Interface
    • MATLAB 限制(验证)接口函数类的集合(验证各种限制条件的函数类)
  • matlab.unittest.diagnostics
    • Summary of classes in MATLAB Diagnostics Interface
    • MATLAB 诊断接口函数类的集合(测试失败时用来诊断的函数类)
  • matlab.unittest.fixtures
    • Summary of classes in MATLAB Fixtures Interface
    • MATLAB 环境接口函数类的集合(准备和清理测试环境的函数类)
  • matlab.unittest.qualifications
    • Summary of classes in MATLAB Qualifications Interface
    • MATLAB 资格(验证)接口函数类(测试例外处理的函数类)

Run Unit Tests 运行单元测试

Run test suites in the testing framework
在测试框架下运行测试套件

Functions 函数

Classes 类

Packages 包

Analyze Test Results 分析测试结果

Use test results to identify failures
使用测试结果来鉴定出错原因

Classes 类

Other Testing Resources