MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
results2 = run(t2);

% Run tests using dot notation
results1 = t1.run;
results2 = t2.run;

Alternatively, you can run tests contained in a single file by using runtests or from the
Editor.

Run Single Test in Class or Function


Run a single test from within a class-based test file by specifying the test method as an
input argument to the run method. For example, only run the test,
testMultiplication, from the DocPolynomTest file.

results1 = run(DocPolynomTest,'testMultiplication');

Function-based test files return an array of Test objects instead of a single TestCase
object. You can run a particular test by indexing into the array. However, you must
examine the Name field in the test array to ensure you run the correct test. For example,
only run the test, surfaceColorTest, from the axesPropertiesTest file.

t2 = axesPropertiesTest; % Test object from function-based test
t2(:).Name

ans =

axesPropertiesTest/testDefaultXLim

ans =

axesPropertiesTest/surfaceColorTest

The surfaceColorTest test corresponds to the second element in the array.

Only run the surfaceColorTest test.

results2 = t2(2).run; % or results2 = run(t2(2));

Alternatively, you can run a single test from the Editor.

33 Unit Testing

Free download pdf