run
Class: matlab.unittest.TestRunner
Namespace: matlab.unittest
Run test suite
Description
Input Arguments
runner
— Test runner
matlab.unittest.TestRunner
object
Test runner, specified as a matlab.unittest.TestRunner
object.
suite
— Test suite
matlab.unittest.TestSuite
array
Test suite, specified as a matlab.unittest.TestSuite
array.
Output Arguments
results
— Results of running test suite
matlab.unittest.TestResult
array
Results of running the test suite, returned as a matlab.unittest.TestResult
array. Elements of results
correspond to the elements of suite
.
Examples
Display Test Results in Command Window
Run a suite of tests with a test runner that is configured for text output.
Create a function-based test sampleTest.m
in your current folder.
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
Create a test suite from the tests in sampleTest.m
.
suite = testsuite("sampleTest.m");
Create a test runner that produces text output and use it to run the tests. The text output includes test run progress as well as diagnostics in the event of test failures.
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.
Display the results from the failing test.
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.
Version History
Introduced in R2013a
See Also
testrunner
| testsuite
| runtests
| run (TestSuite)
| run
(TestCase)
| runInParallel
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)