assertSuccess
类: matlab.unittest.TestResult
命名空间: matlab.unittest
说明
输入参数
results
— 运行测试套件的结果
matlab.unittest.TestResult
数组
运行与测试会话对应的测试套件的结果,指定为 matlab.unittest.TestResult
数组。
示例
测试会话失败时引发异常
运行一个测试套件,如果任一测试失败,则引发异常。
在当前文件夹中,创建一个包含 ExampleTest
类的文件。verifySize
验证导致测试失败。
classdef ExampleTest < matlab.unittest.TestCase methods(Test) function testOne(testCase) % Test fails testCase.verifySize([1 2 3; 4 5 6],[2 4]) end function testTwo(testCase) % Test passes testCase.verifyClass(@sin,?function_handle) end function testThree(testCase) % Test passes testCase.assertEqual(7*2,14) end end end
在命令提示符下,运行 ExampleTest
中的测试,并断言没有遇到失败条件。MATLAB 由于其中一个测试失败而抛出错误。
results = assertSuccess(runtests('ExampleTest'));
Running ExampleTest
================================================================================
Verification failed in ExampleTest/testOne.
---------------------
Framework Diagnostic:
---------------------
verifySize failed.
--> The value had an incorrect size.
Actual Size:
2 3
Expected Size:
2 4
Actual Value:
1 2 3
4 5 6
------------------
Stack Information:
------------------
In C:\Users\username\Desktop\ExampleTest.m (ExampleTest.testOne) at 4
================================================================================
...
Done ExampleTest
__________
Failure Summary:
Name Failed Incomplete Reason(s)
==================================================================
ExampleTest/testOne X Failed by verification.
Error using matlab.unittest.internal.BaseTestResult/assertSuccess (line 125)
At least one test failed in the test session.
提示
使用
assertSuccess
作为验证步骤,以确保您的测试不会产生任何失败。例如,当您在持续集成平台(如 Jenkins®)上执行自动编译时,如果assertSuccess
生成错误,您可以指示编译失败。
版本历史记录
在 R2020a 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)