MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
end
end

Add Plugin to Test Runner and Run Tests

At the command prompt, create a test suite from the ExampleTest class, and create a
test runner.

import matlab.unittest.TestSuite
import matlab.unittest.TestRunner

suite = TestSuite.fromClass(?ExampleTest);
runner = TestRunner.withNoPlugins;

Create an instance of ExampleCustomPlugin and add it to the test runner. Run the
tests.

import matlab.unittest.plugins.ToFile
fname = 'YPS_test_results.txt';
p = ExampleCustomPlugin(ToFile(fname));

runner.addPlugin(p)
result = runner.run(suite);

View the contents of the output file.

type(fname)

--- NEW TEST SESSION at 26-Jan-2015 10:41:24 ---
### YPS Company - Test PASSED ### - ExampleTest/testOne in 0.123284 seconds.
### YPS Company - Test FAILED ### - ExampleTest/testTwo in 0.090363 seconds.
### YPS Company - Test SKIPPED ### - ExampleTest/testThree in 0.518044 seconds.
### YPS Company - Test PASSED ### - ExampleTest/testFour in 0.020599 seconds.

Rerun the Incomplete tests using the same test runner. View the contents of the output
file.

suiteFiltered = suite([result.Incomplete]);
result2 = runner.run(suiteFiltered);

type(fname)

--- NEW TEST SESSION at 26-Jan-2015 10:41:24 ---

33 Unit Testing

Free download pdf