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 resultsNew 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 classesAs 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 frameworkThe
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, seematlab.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 theTestRunner
. 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 thematlab.unittest.selectors
package, allows for the improved selection of tests included in the test suite.
matlab.unittest
plugin for Test Anything Protocol (TAP) outputThe
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 thematlab.unittest.plugins.TAPPlugin
documentation.Output stream direction for
matlab.unittest
pluginsThe
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
, andbandwidth
functions for testing matrix structureThe 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 类
matlab.unittest.TestCase
- Superclass of all matlab.unittest test classes
- 所有matlab.unittest测试类的基类
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 函数
runtests
- Run set of tests
- 运行测试用例集
matlab.unittest.TestCase.run
- Run TestCase test
- 运行 TestCase 测试用例
matlab.unittest.TestSuite.run
- Run TestSuite array using TestRunner object configured for text output
- 使用带有文本输出配置的 TestRunner 运行 TestSuite 测试用例组
matlab.unittest.TestRunner.run
- Run all tests in TestSuite array
- 运行 TestSuite 组中的所有测试用例
matlab.unittest.TestRunner.addPlugin
- Add plugin to TestRunner object
- 向 TestRunner 对象中添加插件
Classes 类
matlab.unittest.TestSuite
- Class for grouping tests to run
- 运行测试用例组
matlab.unittest.Test
- Specification of a single test method
- 单独的测试方法函数定义
matlab.unittest.TestRunner
- Class for running tests in
matlab.unittest
framework- 运行
matlab.unittest
单元测试的框架类
Packages 包
matlab.unittest.parameters
- Summary of classes associated with MATLAB Unit Test parameters
- MATLAB 单元测试参数函数类集合
matlab.unittest.plugins
- Summary of classes in MATLAB Plugins Interface
- MATLAB 插件接口函数类集合
matlab.unittest.plugins.plugindata
- Summary of classes in MATLAB Plugin Data Interface
- MATLAB 插件数据接口函数类集合
matlab.unittest.selectors
- Summary of classes in MATLAB Selectors Interface
- MATLAB 筛选接口函数类集合
Analyze Test Results 分析测试结果
Use test results to identify failures
使用测试结果来鉴定出错原因
Classes 类
matlab.unittest.TestResult
- Result of running test suite
- 测试用例套件的运行结果