Main Content

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(v) constructs a TestRunProgressPlugin for the specified verbosity.

matlab.unittest.plugins.TestRunProgressPlugin.withVerbosity(v,stream) redirects the text output to the output stream.

Input Arguments

expand all

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 RepresentationEnumeration Member NameVerbosity Description
0None

No information

1Terse

Minimal information

2Concise

Moderate amount of information

3Detailed

Some supplemental information

4Verbose

Lots of supplemental information

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

collapse all

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
__________

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