Class-Based Unit Tests
Write xUnit-style tests to check that the output of MATLAB®代码是您期望的。基于类的单元测试可让您访问完整的单元测试框架功能。例如,您可以编写参数化测试,标记测试或使用共享的测试固定装置。
To get started, seeAuthor Class-Based Unit Tests in MATLAB和Write Simple Test Case Using Classes.
Functions
运行测试 |
Run set of tests |
testsuite |
创建测试套件 |
matlab.untest.TestSuite.run |
使用为文本输出配置的TestRunner对象运行测试仪数组 |
matlab.untest.TestRunner.run |
Run all tests in TestSuite array |
Classes
matlab.untest.TestCase |
Superclass of all matlab.unittest test classes |
matlab.untest.TestSuite |
Class for grouping tests to run |
matlab.untest.Test |
单个测试方法的规范 |
matlab.untest.TestRunner |
Class for running tests in matlab.unittest framework |
matlab.unittest.testresult |
Result of running test suite |
软件包
matlab.untest |
MATLAB单元测试框架中包装和类的摘要 |
matlab.untest.qualifications |
MATLAB资格接口中的课程摘要 |
matlab.untest.constraints |
Summary of classes in MATLAB Constraints Interface |
matlab.unittest.diarostics |
Summary of classes in MATLAB Diagnostics Interface |
matlab.untest.fixtures |
Summary of classes in MATLAB Fixtures Interface |
matlab.untest.parameters |
与MATLAB单位测试参数相关的类摘要 |
matlab.unittest.plugins |
Summary of classes in MATLAB Plugins Interface |
matlab.unittest.seletors |
Summary of classes in MATLAB Selectors Interface |
Topics
Write Tests
Author Class-Based Unit Tests in MATLAB
To test a MATLAB program, write a unit test using qualifications that are methods for testing values and responding to failures.
Qualifications are functions for testing values and responding to failures. This summary describes the four types of qualifications and qualification functions that are available in the MATLAB unit testing framework.
Write Simple Test Case Using Classes
This example shows how to write a class-based unit test.
Write Setup and Teardown Code Using Classes
Setup and teardown code, or test fixtures, sets up the pretest state of the system and returns it to the original state after running the test. You can define setup and teardown methods that run before and after each test method or all test methods in a test class.
使用测试标签将测试分为类别,然后使用指定标签运行测试。典型的测试标签识别特定功能或描述测试类型。
Write Tests Using Shared Fixtures
You can share test fixtures across test classes. This example shows how to use shared fixtures when creating tests.
此示例显示了如何创建基本的参数化测试。
Create Advanced Parameterized Test
此示例显示了如何创建在参数中的测试TestClassSetup
,TestMethodSetup
, 和Test
methods
块。
Run Tests and Analyze Results
This example shows how to combine tests into test suites, whether they are organized in packages and classes or files and folders, or both.
This example shows how to run a test, while working in the Editor.
Run Tests for Various Workflows
Explore different ways to run tests.
Programmatically Access Test Diagnostics
If you run tests with the运行测试
function or therun
method ofTestSuite
或者TestCase
, the test framework uses aDiagnosticsRecorDingPlugin
plugin that records diagnostics on test results.
This example shows how to add a plugin to the test runner.
此示例显示了如何分析测试跑步者返回的信息。
This example shows how to identify and handle failed tests.
Rerun failed tests quickly and conveniently.
Assumption failures produce filtered tests that are marked as不完整
而不是产生测试失败。为避免未执行的测试代码,请监视过滤测试。