Package: matlab.unittest.plugins
Plugin that reports test run progress
The TestRunProgressPlugin
class creates a plugin that reports on test run progress.
matlab.unittest.plugins.TestRunProgressPlugin.withVerbosity(
constructs a v
)TestRunProgressPlugin
for the specified verbosity.
matlab.unittest.plugins.TestRunProgressPlugin.withVerbosity(
redirects the text output to the output stream.v
,stream
)
v
— Verbosity level0
| 1
| 2
| 3
| 4
| matlab.unittest.Verbosity
enumeration | enumeration name as string or char vectorVerbosity level, specified as an integer value between 0 and 4, a matlab.unittest.Verbosity
enumeration object, or a string scalar or character vector corresponding to one of the predefined enumeration member names. Integer values correspond to the members of the matlab.unittest.Verbosity
enumeration.
Numeric Representation | Enumeration Member Name | Verbosity Description |
---|---|---|
0 | None | No information |
1 | Terse | Minimal information |
2 | Concise | Moderate amount of information |
3 | Detailed | Some supplemental information |
4 | Verbose | Lots of supplemental information |
stream
— Location where plugin directs text outputToStandardOutput
instance (default) | OutputStream
instanceLocation where the plugin directs text output, specified as an OutputStream
instance. By default, the plugin uses the OutputStream
subclass ToStandardOutput
as the stream.
Handle. To learn how handle classes affect copy operations, see Copying Objects.
Create a function-based test called cylinderPlotTest
in a file in your working folder.
function tests = cylinderPlotTest tests = functiontests(localfunctions); end function setupOnce(testCase) testCase.TestData.Figure = figure; addTeardown(testCase,@close,testCase.TestData.Figure) end function setup(testCase) testCase.TestData.Axes = axes('Parent',testCase.TestData.Figure); addTeardown(testCase,@clf,testCase.TestData.Figure) cylinder(testCase.TestData.Axes,10) end function testXLim(testCase) xlim = testCase.TestData.Axes.XLim; verifyLessThanOrEqual(testCase,xlim(1),-10,'Minimum x-limit too large') verifyGreaterThanOrEqual(testCase,xlim(2),10,'Maximum x-limit too small') end function zdataTest(testCase) s = findobj(testCase.TestData.Axes,'Type','surface'); verifyEqual(testCase,min(s.ZData(:)),0,'Min cylinder value is incorrect') verifyEqual(testCase,max(s.ZData(:)),1,'Max cylinder value is incorrect') end
At the command prompt, run the test.
results = run(cylinderPlotTest);
Running cylinderPlotTest .. Done cylinderPlotTest __________
By default, the test runner uses verbosity level 2.
Create a test runner to report the diagnostics at level 1, and rerun the test.
import matlab.unittest.TestRunner import matlab.unittest.plugins.TestRunProgressPlugin runner = TestRunner.withNoPlugins; p = TestRunProgressPlugin.withVerbosity(1); runner.addPlugin(p); results = runner.run(cylinderPlotTest);
..
Create a test runner to report the diagnostics at level 4, and rerun the test.
runner = TestRunner.withNoPlugins; p = TestRunProgressPlugin.withVerbosity(4); runner.addPlugin(p); results = runner.run(cylinderPlotTest);
Running cylinderPlotTest Setting up cylinderPlotTest Evaluating TestClassSetup: setupOnce Done setting up cylinderPlotTest in 0.067649 seconds Running cylinderPlotTest/testXLim Evaluating TestMethodSetup: setup Evaluating Test: testXLim Evaluating TestMethodTeardown: teardown Evaluating addTeardown function: clf Done cylinderPlotTest/testXLim in 0.053834 seconds Running cylinderPlotTest/zdataTest Evaluating TestMethodSetup: setup Evaluating Test: zdataTest Evaluating TestMethodTeardown: teardown Evaluating addTeardown function: clf Done cylinderPlotTest/zdataTest in 0.037715 seconds Tearing down cylinderPlotTest Evaluating TestClassTeardown: teardownOnce Evaluating addTeardown function: close Done tearing down cylinderPlotTest in 0.022783 seconds Done cylinderPlotTest in 0.18198 seconds __________
Create a class named ExampleProgressTest
in a file in your current working folder.
classdef ExampleProgressTest < matlab.unittest.TestCase methods(Test) function testOne(testCase) % Test fails testCase.verifyEqual(5,4) end function testTwo(testCase) % Test passes testCase.verifyEqual(5,5) end end end
At the command prompt, create the test suite and a runner at verbosity level 3, and then run the test.
import matlab.unittest.TestSuite import matlab.unittest.TestRunner import matlab.unittest.plugins.TestRunProgressPlugin suite = TestSuite.fromClass(?ExampleProgressTest); runner = TestRunner.withNoPlugins; p = TestRunProgressPlugin.withVerbosity(3); runner.addPlugin(p); results = runner.run(suite);
Running ExampleProgressTest Setting up ExampleProgressTest Done setting up ExampleProgressTest in 0 seconds Running ExampleProgressTest/testOne Done ExampleProgressTest/testOne in 0.0049988 seconds Running ExampleProgressTest/testTwo Done ExampleProgressTest/testTwo in 0.0044541 seconds Tearing down ExampleProgressTest Done tearing down ExampleProgressTest in 0 seconds Done ExampleProgressTest in 0.0094529 seconds __________
Create a new plugin to direct the output to a file named myOutput.log
, and rerun the tests.
import matlab.unittest.plugins.ToFile outFile = 'myOutput.log'; runner = TestRunner.withNoPlugins; p = TestRunProgressPlugin.withVerbosity(3,ToFile(outFile)); runner.addPlugin(p); results = runner.run(suite);
Observe the contents of the file created by the plugin.
disp(fileread(outFile))
Running ExampleProgressTest Setting up ExampleProgressTest Done setting up ExampleProgressTest in 0 seconds Running ExampleProgressTest/testOne Done ExampleProgressTest/testOne in 0.0050172 seconds Running ExampleProgressTest/testTwo Done ExampleProgressTest/testTwo in 0.0049449 seconds Tearing down ExampleProgressTest Done tearing down ExampleProgressTest in 0 seconds Done ExampleProgressTest in 0.009962 seconds __________
matlab.unittest.plugins.OutputStream
| matlab.unittest.plugins.TestRunnerPlugin
| matlab.unittest.plugins.ToStandardOutput
| matlab.unittest.TestRunner
| matlab.unittest.Verbosity