matlab.unittest.plugins.TestRunProgressPlugin Class
Namespace: matlab.unittest.plugins
Plugin that reports test run progress
Description
The TestRunProgressPlugin
class creates a plugin that reports on test run progress.
Construction
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
)
Input Arguments
v
— Verbosity level
0
| 1
| 2
| 3
| 4
| matlab.automation.Verbosity
enumeration | enumeration name as string or char vector
Verbosity level, specified as an integer value between 0 and 4, a
matlab.automation.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.automation.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 output
ToStandardOutput
instance (default) | OutputStream
instance
Location where the plugin directs text output, specified as an OutputStream
instance. By default, the plugin uses the OutputStream
subclass ToStandardOutput
as the stream.
Copy Semantics
Handle. To learn how handle classes affect copy operations, see Copying Objects.
Examples
Create Test Run Progress Plugin
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 __________
Configure Progress Message Output
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.018872 seconds Running ExampleProgressTest/testTwo Done ExampleProgressTest/testTwo in 0.0031567 seconds Tearing down ExampleProgressTest Done tearing down ExampleProgressTest in 0 seconds Done ExampleProgressTest in 0.022029 seconds __________
Create a new plugin to direct the output to a file named myOutput.log
, and rerun the tests.
import matlab.automation.streams.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.014028 seconds Running ExampleProgressTest/testTwo Done ExampleProgressTest/testTwo in 0.0020934 seconds Tearing down ExampleProgressTest Done tearing down ExampleProgressTest in 0 seconds Done ExampleProgressTest in 0.016122 seconds __________
Version History
Introduced in R2014b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)