matlab.automation.streams.ToStandardOutput class
Package: matlab.automation.streams
Superclasses: matlab.automation.streams.OutputStream
Output stream to write text to screen
Renamed from matlab.unittest.plugins.ToStandardOutput
in R2023a
Description
The matlab.automation.streams.ToStandardOutput
class provides an output
stream to write text to the screen. Many text-oriented plugins that accept an output stream
use a ToStandardOutput
instance as their default stream.
The matlab.automation.streams.ToStandardOutput
class is a handle
class.
Creation
stream = matlab.automation.streams.ToStandardOutput
creates an output
stream to write text to the screen.
Examples
Display the Names of Running Tests
Run tests using a plugin that directs the names of tests being run to an output stream. Pass a ToStandardOutput
instance to the plugin so that it directs the text it produces to the screen.
Create Custom Plugin
In a file named ExamplePlugin.m
in your current folder, create the ExamplePlugin
class, which overrides the runTest
method of TestRunnerPlugin
. The plugin directs the name of each test being run to the output stream specified during construction of the plugin.
classdef ExamplePlugin < matlab.unittest.plugins.TestRunnerPlugin properties (SetAccess=immutable) Output end methods function plugin = ExamplePlugin(stream) arguments stream (1,1) matlab.automation.streams.OutputStream end plugin.Output = stream; end end methods (Access=protected) function runTest(plugin,pluginData) print(plugin.Output,"### Running test: %s\n",pluginData.Name) % Invoke the superclass method runTest@matlab.unittest.plugins.TestRunnerPlugin( ... plugin,pluginData) end end end
Create Example Test Class
In a file named ZerosTest.m
in your current folder, create the ZerosTest
class, which tests the zeros
function.
classdef ZerosTest < matlab.unittest.TestCase properties (TestParameter) type = {'single','double','uint16'}; size = struct("s2d",[3 3],"s3d",[2 5 4]); end methods (Test) function testClass(testCase,size,type) testCase.verifyClass(zeros(size,type),type) end function testSize(testCase,size) testCase.verifySize(zeros(size),size) end function testDefaultClass(testCase) testCase.verifyClass(zeros,"double") end function testDefaultSize(testCase) testCase.verifySize(zeros,[1 1]) end function testDefaultValue(testCase) testCase.verifyEqual(zeros,0) end end end
Add Plugin to Test Runner and Run Tests
To run the tests, first import the classes used in this example.
import matlab.unittest.TestRunner import matlab.automation.streams.ToStandardOutput
Create a test suite from the ZerosTest
class.
suite = testsuite("ZerosTest");
Create a test runner with no plugins. This code creates a silent runner that produces no output.
runner = testrunner("minimal");
You can now add any plugins you choose. Create an ExamplePlugin
instance that directs text output to the screen.
plugin = ExamplePlugin(ToStandardOutput);
Add the plugin to the test runner and run the tests. As the tests run, the names of the tests appear on the screen.
runner.addPlugin(plugin) results = runner.run(suite);
### Running test: ZerosTest/testClass(size=s2d,type=single) ### Running test: ZerosTest/testClass(size=s2d,type=double) ### Running test: ZerosTest/testClass(size=s2d,type=uint16) ### Running test: ZerosTest/testClass(size=s3d,type=single) ### Running test: ZerosTest/testClass(size=s3d,type=double) ### Running test: ZerosTest/testClass(size=s3d,type=uint16) ### Running test: ZerosTest/testSize(size=s2d) ### Running test: ZerosTest/testSize(size=s3d) ### Running test: ZerosTest/testDefaultClass ### Running test: ZerosTest/testDefaultSize ### Running test: ZerosTest/testDefaultValue
Version History
Introduced in R2014aR2023a: Renamed from matlab.unittest.plugins.ToStandardOutput
To reflect support for additional automated workflows,
matlab.unittest.plugins.ToStandardOutput
is now named
matlab.automation.streams.ToStandardOutput
. The behavior of this class
remains the same, and existing instances of
matlab.unittest.plugins.ToStandardOutput
in your code continue to work as
expected. There are no plans to remove support for existing instances of
matlab.unittest.plugins.ToStandardOutput
.
Abrir ejemplo
Tiene una versión modificada de este ejemplo. ¿Desea abrir este ejemplo con sus modificaciones?
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
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)