Run Tests in Editor
When you open a function-based or class-based test file in the MATLAB® Editor, you have the option to run all tests in the file or to run the test at your cursor location. (This functionality is also available when you open a function-based test file in the Live Editor.) This example shows how to run tests while working in the Editor.
In the Editor, create a test in a file named
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
When you save the test, the Run section in the Editor tab changes to Run Tests.
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
Running sampleTest ... Done sampleTest __________ ans = 1×3 TestResult array with properties: Name Passed Failed Incomplete Duration Details Totals: 3 Passed, 0 Failed, 0 Incomplete. 0.0071673 seconds testing time.
In the Editor, place your cursor in the
testB function and
click Run Current Test. MATLAB runs
Running sampleTest . Done sampleTest __________ ans = TestResult with properties: Name: 'sampleTest/testB' Passed: 1 Failed: 0 Incomplete: 0 Duration: 9.9411e-04 Details: [1×1 struct] Totals: 1 Passed, 0 Failed, 0 Incomplete. 0.00099411 seconds testing time.
In addition to running tests, you can customize the test run using the test options under Run Tests. (Click the down arrow under Run Tests to access the full option list.) MATLAB uses test options whether you run all the tests in a file or just the test at your cursor location. When you select a test option, the selection persists for the duration of your current MATLAB session.
Clear Output Before Running Tests
Clears the Command Window before running tests.
Applies strict checks while running tests. For example, the framework generates a qualification failure if a test issues a warning.
Tests that run with this
option selected have the
Runs tests in parallel. This option is only available if Parallel Computing Toolbox™ is installed.
Tests that run with
this option selected have the
Controls the amount of detail displayed for a test run.
For example, tests that run with Output
Detail specified as 0: None have the
Displays diagnostics logged by the
example, tests that run with Logging Level specified as
3: Detailed have the
You can also run the tests of this example in the Live Editor by saving them
in a file with a
.mlx extension and using the
Run section in the Live Editor