matlab.unittest.plugins.TestRunProgressPlugin.withVerbosity
Class: matlab.unittest.plugins.TestRunProgressPlugin
Namespace: matlab.unittest.plugins
Create plugin that displays test run progress at specified verbosity
Syntax
Description
plugin = matlab.unittest.plugins.TestRunProgressPlugin.withVerbosity(
creates a plugin that displays test run progress at the specified verbosity level. By
default, the plugin directs its text output to the screen.level)
Input Arguments
Verbosity level, specified as an integer scalar from 0 through
4, a matlab.automation.Verbosity enumeration
object, or a text representation of the 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 |
Example: 3
Example: "Detailed"
Output stream where the plugin directs text output, specified as a matlab.automation.streams.OutputStream object. By default, the plugin directs
its output to the screen.
Example: matlab.automation.streams.ToFile("myFile.txt")
Examples
Run tests and control the amount of information to display by using the
TestRunProgressPlugin class.
In a file named cylinderPlotTest.m in your current folder, create
function-based tests to test a cylinder plot.
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) verifyGreaterThanOrEqual(testCase,xlim(2),10) end function zdataTest(testCase) s = findobj(testCase.TestData.Axes,"Type","surface"); verifyEqual(testCase,min(s.ZData(:)),0) verifyEqual(testCase,max(s.ZData(:)),1) end
Import the TestRunProgressPlugin class.
import matlab.unittest.plugins.TestRunProgressPluginCreate a test suite from the test file.
suite = testsuite("cylinderPlotTest.m");Run the tests using a default test runner. The test runner displays test run progress at
the matlab.automation.Verbosity.Concise level (level 2).
runner = testrunner; results = runner.run(suite);
Running cylinderPlotTest .. Done cylinderPlotTest __________
Create a new test runner and configure it using a plugin that displays test run progress
at the matlab.automation.Verbosity.Terse level (level 1). Then, rerun the
tests using the test runner.
runner = testrunner("minimal"); plugin = TestRunProgressPlugin.withVerbosity("Terse"); runner.addPlugin(plugin) results = runner.run(suite);
..
Rerun the tests and display test run progress at the
matlab.automation.Verbosity.Verbose level (level 4), which is the highest
verbosity level.
runner = testrunner("minimal"); plugin = TestRunProgressPlugin.withVerbosity("Verbose"); runner.addPlugin(plugin) results = runner.run(suite);
Running cylinderPlotTest
Setting up cylinderPlotTest
Evaluating TestClassSetup: setupOnce
Done setting up cylinderPlotTest in 0.093533 seconds
Running cylinderPlotTest/testXLim
Evaluating TestMethodSetup: setup
Evaluating Test: testXLim
Evaluating TestMethodTeardown: teardown
Evaluating addTeardown function: clf
Done cylinderPlotTest/testXLim in 0.15021 seconds
Running cylinderPlotTest/zdataTest
Evaluating TestMethodSetup: setup
Evaluating Test: zdataTest
Evaluating TestMethodTeardown: teardown
Evaluating addTeardown function: clf
Done cylinderPlotTest/zdataTest in 0.028826 seconds
Tearing down cylinderPlotTest
Evaluating TestClassTeardown: teardownOnce
Evaluating addTeardown function: close
Done tearing down cylinderPlotTest in 0.018563 seconds
Done cylinderPlotTest in 0.29114 seconds
__________
Control the verbosity level and location to display test run progress
information by using the TestRunProgressPlugin class.
In a file named ExampleTest.m in your current folder, create
the ExampleTest test class.
classdef ExampleTest < 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
Import the classes used in this example.
import matlab.unittest.plugins.TestRunProgressPlugin import matlab.automation.streams.ToFile
Create a test suite from the ExampleTest class.
suite = testsuite("ExampleTest");Using a TestRunProgressPlugin instance, run the tests and display
test run progress at the matlab.automation.Verbosity.Detailed level
(level 3). By default, the plugin directs its text output to the screen.
runner = testrunner("minimal"); plugin = TestRunProgressPlugin.withVerbosity("Detailed"); runner.addPlugin(plugin) results = runner.run(suite);
Running ExampleTest Setting up ExampleTest Done setting up ExampleTest in 0 seconds Running ExampleTest/testOne Done ExampleTest/testOne in 0.54909 seconds Running ExampleTest/testTwo Done ExampleTest/testTwo in 0.011 seconds Tearing down ExampleTest Done tearing down ExampleTest in 0 seconds Done ExampleTest in 0.56009 seconds __________
Create a new test runner and configure it using a plugin that directs its output
to a file named myOutput.log in your current folder. If you rerun
the tests, the information on test run progress no longer appears in the Command
Window. The plugin directs the text output to the specified file instead of the
screen.
runner = testrunner("minimal"); plugin = TestRunProgressPlugin.withVerbosity( ... "Detailed",ToFile("myOutput.log")); runner.addPlugin(plugin) results = runner.run(suite);
Display the contents of the file created by the plugin.
disp(fileread("myOutput.log"))Running ExampleTest Setting up ExampleTest Done setting up ExampleTest in 0 seconds Running ExampleTest/testOne Done ExampleTest/testOne in 0.051384 seconds Running ExampleTest/testTwo Done ExampleTest/testTwo in 0.0099046 seconds Tearing down ExampleTest Done tearing down ExampleTest in 0 seconds Done ExampleTest in 0.061288 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.
Seleccione un país/idioma
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
Cómo obtener el mejor rendimiento
Seleccione China (en idioma chino o inglés) para obtener el mejor rendimiento. Los sitios web de otros países no están optimizados para ser accedidos desde su ubicación geográfica.
América
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- 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)