run
类: matlab.unittest.TestRunner
命名空间: matlab.unittest
运行测试套件
说明
输入参数
runner
— 测试运行器
matlab.unittest.TestRunner
对象
测试运行器,指定为 matlab.unittest.TestRunner
对象。
suite
— 测试套件
matlab.unittest.TestSuite
数组
测试套件,指定为 matlab.unittest.TestSuite
数组。
输出参量
results
— 运行测试套件的结果
matlab.unittest.TestResult
数组
运行测试套件的结果,以 matlab.unittest.TestResult
数组形式返回。results
的元素对应于 suite
的元素。
示例
在命令行窗口中显示测试结果
使用为文本输出配置的测试运行器运行一组测试。
在当前文件夹中创建一个基于函数的测试 sampleTest.m
。
function tests = sampleTest tests = functiontests(localfunctions); end function testA(testCase) % Test passes verifyEqual(testCase,2+3,5) end function testB(testCase) % Test fails verifyGreaterThan(testCase,13,42) end function testC(testCase) % Test passes verifySubstring(testCase,"Hello world!","llo") end
基于 sampleTest.m
中的测试创建一个测试套件。
suite = testsuite("sampleTest.m");
创建一个生成文本输出的测试运行器,并使用它来运行测试。文本输出包括测试运行进度以及在测试失败时的诊断。
runner = testrunner("textoutput");
results = run(runner,suite);
Running sampleTest . ================================================================================ Verification failed in sampleTest/testB. --------------------- Framework Diagnostic: --------------------- verifyGreaterThan failed. --> The value must be greater than the minimum value. Actual Value: 13 Minimum Value (Exclusive): 42 ------------------ Stack Information: ------------------ In C:\work\sampleTest.m (testB) at 10 ================================================================================ .. Done sampleTest __________ Failure Summary: Name Failed Incomplete Reason(s) =============================================================== sampleTest/testB X Failed by verification.
显示失败测试的结果。
disp(results([results.Failed]))
TestResult with properties: Name: 'sampleTest/testB' Passed: 0 Failed: 1 Incomplete: 0 Duration: 1.2982 Details: [1×1 struct] Totals: 0 Passed, 1 Failed (rerun), 0 Incomplete. 1.2982 seconds testing time.
版本历史记录
在 R2013a 中推出
另请参阅
testrunner
| testsuite
| runtests
| run (TestSuite)
| run
(TestCase)
| runInParallel
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)