function [x,y] = exampleFunction(n)
validateattributes(n,{'numeric'},{'scalar'})
x = n^2; % square
y = sqrt(n); % square root
end
Click the (rerun) link in the command window to rerun the failed test. You cannot rerun
failed tests if the variable that stores the test results is overwritten. If the link is no longer
in the Command Window, you can type results at the prompt to view it.
Running exampleTest
.
Done exampleTest
__________
ans =
TestResult with properties:
Name: 'exampleTest/testSquare'
Passed: 1
Failed: 0
Incomplete: 0
Duration: 0.0034
Details: [1×1 struct]
Totals:
1 Passed, 0 Failed, 0 Incomplete.
0.0033903 seconds testing time.
MATLAB stores the TestResult array associated with tests that you rerun in the ans
variable. results is a 1x2 array that contains all the tests in exampleTest.m, and ans
is a 1x1 array that contains the rerun results from the one failed test.
whos
Name Size Bytes Class Attributes
ans 1x1 664 matlab.unittest.TestResult
results 1x2 1344 matlab.unittest.TestResult
suite 1x2 96 matlab.unittest.Test
To programmatically rerun failed tests, use the Failed property on the TestResult
object to create and run a filtered test suite.
33 Unit Testing