matlab.unittest.TestRunner.run - Run test suite - MATLAB (original) (raw)
Main Content
Class: matlab.unittest.TestRunner
Namespace: matlab.unittest
Syntax
Description
[results](#mw%5Fc94269d5-924b-486f-87f7-a8f023148e62) = run([runner](#mw%5F7ba286d5-4f10-4f65-8d1b-6e46ac4260df),[suite](#mw%5Fffd8c74d-ebf0-45cb-8a68-3a96d4318312))
runs the TestSuite
array suite
using the specified test runner and returns the results of the test run. When running the test suite, the method automatically exercises any setup and teardown code required by the tests.
Input Arguments
Test runner, specified as a matlab.unittest.TestRunner
object.
Examples
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