matlab.unittest.plugins.TestRunProgressPlugin 类
命名空间: matlab.unittest.plugins
报告测试运行进度的插件
描述
TestRunProgressPlugin 类创建一个报告测试运行进度的插件。
构造
matlab.unittest.plugins.TestRunProgressPlugin.withVerbosity( 为指定的详细级别构造 v)TestRunProgressPlugin。
matlab.unittest.plugins.TestRunProgressPlugin.withVerbosity( 将文本输出重定向到输出流。v,stream)
输入参数
详细级别,指定为介于 0 和 4 之间的整数值、matlab.automation.Verbosity 枚举对象,或对应于预定义枚举成员名称之一的字符串标量或字符向量。整数值对应于 matlab.automation.Verbosity 枚举的成员。
| 数值表示 | 枚举成员名称 | 详细程度描述 |
|---|---|---|
0 | None | 无信息 |
1 | Terse | 最少的信息 |
2 | Concise | 适中信息量 |
3 | Detailed | 部分补充信息 |
4 | Verbose | 大量补充信息 |
插件定向文本输出的位置,指定为 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 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.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)