matlab.unittest.plugins.TAPPlugin.producingVersion13

Class: matlab.unittest.plugins.TAPPlugin
Package: matlab.unittest.plugins

Construct TAPPlugin for version 13 TAP format

Syntax

  • matlab.unittest.plugins.TAPPlugin.producingVersion13
    example
  • matlab.unittest.plugins.TAPPlugin.producingVersion13(stream)
  • matlab.unittest.plugins.TAPPlugin.producingVersion13(___,Name,Value)

Description

example

matlab.unittest.plugins.TAPPlugin.producingVersion13 creates a plugin that produces output in version 13 of the Test Anything Protocol (TAP) format. The TAP version 13 output includes test diagnostics in YAML blocks. By default, the plugin uses the ToStandardOutput stream, and the output appears on the screen. In this case, other output sent to the screen can invalidate the TAP stream.

matlab.unittest.plugins.TAPPlugin.producingVersion13(stream) redirects all the text output to a specified output stream. For example, you can redirect the output to the ToFile stream.

matlab.unittest.plugins.TAPPlugin.producingVersion13(___,Name,Value) creates a plugin with additional options specified by one or more Name,Value pair arguments.

Input Arguments

expand all

Location where the plugin directs text output, specified as an instance of the OutputStream class. By default, the plugin uses the ToStandardOutput stream.

Example: stream = matlab.unittest.plugins.ToStandardOutput

Example: stream = matlab.unittest.plugins.ToFile('myFile.tap')

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: TAPPlugin.producingVersion13('Verbosity', Verbosity.Detailed) creates a plugin that includes diagnostics logged at and below the Detailed level.

expand all

Whether to record diagnostics from passing tests, specified as false or true. By default the plugin does not record diagnostics from passing tests.

Data Types: logical

Verbosity levels recorded by the plugin instance, specified as an integer value from 1 through 4, or as a matlab.unittest.Verbosity enumeration object. The plugin records diagnostics that are logged at this level and below. Integer values correspond to the members of the matlab.unittest.Verbosity enumeration. By default the plugin records diagnostics logged at the matlab.unittest.Verbosity.Terse level.

Numeric RepresentationCorresponding Enumeration ObjectVerbosity Description
1matlab.unittest.Verbosity.Terse

Minimal information

2matlab.unittest.Verbosity.Concise

Moderate amount of information

3matlab.unittest.Verbosity.Detailed

Some supplemental information

4matlab.unittest.Verbosity.Verbose

Lots of supplemental information

Whether to exclude diagnostics from logged events, specified as false or true. By default the plugin does not record diagnostics from logged events.

Data Types: logical

Examples

expand all

In a new file in your working folder, create ExampleTest.m containing the following test class.

classdef ExampleTest < matlab.unittest.TestCase
    methods(Test)
        function testOne(testCase)  % Test fails
            testCase.verifyEqual(5,4,'Testing 5==4')
        end
        function testTwo(testCase)  % Test passes
            testCase.verifyEqual(5,5,'Testing 5==5')
        end
        function testThree(testCase)
            % test code
        end
    end
end

At the command prompt, create a test suite from the ExampleTest class.

import matlab.unittest.TestRunner
import matlab.unittest.TestSuite
import matlab.unittest.plugins.TAPPlugin
import matlab.unittest.plugins.ToFile

suite = TestSuite.fromClass(?ExampleTest);

Create a test runner that displays output to the command window using the default plugin.

runner = TestRunner.withTextOutput;

Create a TAPPlugin that sends output to the file MyTapOutput.tap.

tapFile = 'MyTAPOutput.tap';
plugin = TAPPlugin.producingVersion13(ToFile(tapFile));

Add the plugin to the TestRunner and run the suite.

runner.addPlugin(plugin)
result = runner.run(suite);
Running ExampleTest

================================================================================
Verification failed in ExampleTest/testOne.

    ----------------
    Test Diagnostic:
    ----------------
    Testing 5==4

    ---------------------
    Framework Diagnostic:
    ---------------------
    verifyEqual failed.
    --> The values are not equal using "isequaln".
    --> Failure table:
                Actual    Expected    Error    RelativeError
                ______    ________    _____    _____________
            
                5         4           1        0.25         
    
    Actual double:
             5
    Expected double:
             4

    ------------------
    Stack Information:
    ------------------
    In C:\work\ExampleTest.m (ExampleTest.testOne) at 4
================================================================================
...
Done ExampleTest
__________

Failure Summary:

     Name                 Failed  Incomplete  Reason(s)
    ==================================================================
     ExampleTest/testOne    X                 Failed by verification.

Display the file created by the plugin.

disp(fileread(tapFile))
TAP version 13
1..3
not ok 1 - ExampleTest/testOne
    ---
    Event:
        Event Name: 'VerificationFailed'
        Scope: 'ExampleTest/testOne'
        Test Diagnostic: |
            Testing 5==4
        Framework Diagnostic: |
            verifyEqual failed.
            --> The values are not equal using "isequaln".
            --> Failure table:
                        Actual    Expected    Error    RelativeError
                        ______    ________    _____    _____________
                    
                        5         4           1        0.25         
            
            Actual double:
                     5
            Expected double:
                     4
        Stack: |
            In C:\work\ExampleTest.m (ExampleTest.testOne) at 4
    ...
ok 2 - ExampleTest/testTwo
ok 3 - ExampleTest/testThree

You can use the TAPPlugin directed to standard output. However, any other text displayed to standard output (such as failed test information) interrupts the stream and has the potential to invalidate it.

Introduced in R2016b

Was this topic helpful?