matlab.unittest.plugins.TestRunProgressPlugin 类
报告测试运行进度的插件
描述
TestRunProgressPlugin
类创建一个报告测试运行进度的插件。
构造
matlab.unittest.plugins.TestRunProgressPlugin.withVerbosity(
为指定的详细级别构造 v
)TestRunProgressPlugin
。
matlab.unittest.plugins.TestRunProgressPlugin.withVerbosity(
将文本输出重定向到输出流。v
,stream
)
输入参数
v
— 详细级别
0
| 1
| 2
| 3
| 4
| matlab.automation.Verbosity
枚举 | 枚举名称作为字符串或字符向量
详细级别,指定为介于 0 和 4 之间的整数值、matlab.automation.Verbosity
枚举对象,或对应于预定义枚举成员名称之一的字符串标量或字符向量。整数值对应于 matlab.automation.Verbosity
枚举的成员。
数值表示 | 枚举成员名称 | 详细程度描述 |
---|---|---|
0 | None | 无信息 |
1 | Terse | 最少的信息 |
2 | Concise | 适中信息量 |
3 | Detailed | 部分补充信息 |
4 | Verbose | 大量补充信息 |
stream
— 插件要将文本输出定向到的位置
ToStandardOutput
实例 (默认) | OutputStream
实例
插件定向文本输出的位置,指定为 OutputStream
实例。默认情况下,插件使用 OutputStream
子类 ToStandardOutput
作为流。
复制语义
句柄。要了解句柄类如何影响复制操作,请参阅复制对象。
示例
创建测试运行进度插件
在工作文件夹下的文件中,创建一个名为 cylinderPlotTest
的基于函数的测试。
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
在命令提示符下运行测试。
results = run(cylinderPlotTest);
Running cylinderPlotTest .. Done cylinderPlotTest __________
默认情况下,测试运行程序使用详细级别 2。
创建一个用于报告级别 1 的诊断的测试运行程序,并重新运行该测试。
import matlab.unittest.TestRunner import matlab.unittest.plugins.TestRunProgressPlugin runner = TestRunner.withNoPlugins; p = TestRunProgressPlugin.withVerbosity(1); runner.addPlugin(p); results = runner.run(cylinderPlotTest);
..
创建一个用于报告级别 4 的诊断的测试运行程序,并重新运行该测试。
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 __________
配置进度消息输出
在您的当前工作文件夹下的文件中创建一个名为 ExampleProgressTest
的类。
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
在命令提示符下,创建该测试套件和一个详细级别为 3 的运行程序,然后运行该测试。
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 __________
创建一个新插件以将输出定向到名为 myOutput.log
的文件并返回测试。
import matlab.automation.streams.ToFile outFile = 'myOutput.log'; runner = TestRunner.withNoPlugins; p = TestRunProgressPlugin.withVerbosity(3,ToFile(outFile)); runner.addPlugin(p) results = runner.run(suite);
观察该插件创建的文件的内容。
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 __________
版本历史记录
在 R2014b 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 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)