在编辑器中,在名为 sampleTest.m 的文件中创建一个测试。
function tests = sampleTest
tests = functiontests(localfunctions);
end
function testA(testCase)
verifyEqual(testCase,5,5)
end
function testB(testCase)
verifyGreaterThan(testCase,42,13)
end
function testC(testCase)
verifySubstring(testCase,'hello, world','llo')
end
保存该测试时,编辑器选项卡中的运行部分变为运行测试。
点击运行测试图标。MATLAB 在命令行窗口中显示用于运行测试的命令,然后显示测试输出。MATLAB 运行 sampleTest.m 中的所有三个测试。
runtests('sampleTest')
Running sampleTest
...
Done sampleTest
__________
ans =
1×3 TestResult array with properties:
Name
Passed
F