MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

Run Tests in Editor


This example shows how to run a test while working in the Editor. When you open a
function-based test or class-based test in the Editor, the Editor tab contains a Run Tests
section instead of a Run section. This section provides several options to run the tests in
your current file.

The Run Tests button runs all the tests in the file. The Run Current Test button runs
the test at your current cursor location.

In the Editor, create a test in a file named sampleTest.m. When you save the test, the
Run section in the Editor tab changes to Run Tests.

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

Click the Run Tests icon. MATLAB displays the command it uses to run the tests in the
Command Window, and the test output follows. MATLAB runs all three tests from
sampleTest.m.

runtests('sampleTest')
Running sampleTest
...

Run Tests in Editor
Free download pdf