MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

Run Tests for Various Workflows


In this section...
“Set Up Example Tests” on page 33-105
“Run All Tests in Class or Function” on page 33-105
“Run Single Test in Class or Function” on page 33-106
“Run Test Suites by Name” on page 33-107
“Run Test Suites from Test Array” on page 33-107
“Run Tests with Customized Test Runner” on page 33-107

Set Up Example Tests


To explore different ways to run tests, create a class-based test and a function-based test
in your current working folder. For the class-based test file use the DocPolynomTest
example test presented in the matlab.unittest.qualifications.Verifiable
example. For the function-based test file use the axesPropertiesTest example test
presented in “Write Test Using Setup and Teardown Functions” on page 33-35.

Run All Tests in Class or Function


Use the run method of the TestCase class to directly run tests contained in a single test
file. When running tests directly, you do not need to explicitly create a Test array.

% Directly run a single file of class-based tests
results1 = run(DocPolynomTest);

% Directly run a single file of function-based tests
results2 = run(axesPropertiesTest);

You can also assign the test file output to a variable and run the tests using the functional
form or dot notation.

% Create Test or TestCase objects
t1 = DocPolynomTest; % TestCase object from class-based test
t2 = axesPropertiesTest; % Test object from function-based test

% Run tests using functional form
results1 = run(t1);

Run Tests for Various Workflows
Free download pdf