Main Content

matlab.unittest.plugins.TAPPlugin.producingVersion13

クラス: matlab.unittest.plugins.TAPPlugin
名前空間: matlab.unittest.plugins

version 13 の TAP 形式の TAPPlugin を作成する

説明

matlab.unittest.plugins.TAPPlugin.producingVersion13 は、バージョン 13 の Test Anything Protocol (TAP) 形式の出力を生成するプラグインを作成します。TAP 形式バージョン 13 の出力では YAML ブロックにテスト診断情報が含まれています。既定では、プラグインは ToStandardOutput ストリームを使用し、出力が画面に表示されます。この場合、画面に送られる他の出力によって TAP ストリームが無効になる可能性があります。

matlab.unittest.plugins.TAPPlugin.producingVersion13(stream) は、すべてのテキスト出力を指定された出力ストリームにリダイレクトします。たとえば、出力を ToFile ストリームにリダイレクトできます。

matlab.unittest.plugins.TAPPlugin.producingVersion13(___,Name,Value) は、1 つ以上の Name,Value のペア引数で指定された追加オプションをもつプラグインを作成します。

入力引数

すべて展開する

プラグインがテキスト出力を送信する場所。OutputStream クラスのインスタンスとして指定します。既定では、プラグインは ToStandardOutput ストリームを使用します。

例: stream = matlab.automation.streams.ToStandardOutput

例: stream = matlab.automation.streams.ToFile('myFile.tap')

名前と値の引数

引数のオプションのペアを Name1=Value1,...,NameN=ValueN として指定します。ここで Name は引数名で、Value は対応する値です。名前と値の引数は他の引数の後になければなりませんが、ペアの順序は重要ではありません。

R2021a より前では、コンマを使用してそれぞれの名前と値を区切り、Name を引用符で囲みます。

例: TAPPlugin.producingVersion13('LoggingLevel', Verbosity.Detailed)Detailed 以下のレベルでログに記録された診断を含めるプラグインを作成します。

パスしたイベントの診断を含めるかどうか。false または true として指定します。既定で、プラグインはパスしたイベントの診断を含めません。

データ型: logical

テスト レポートに含める診断ログの最大詳細レベル。0 から 4 までの整数スカラー、matlab.automation.Verbosity 列挙オブジェクト、または列挙のテキスト表現として指定します。プラグインは、指定されたレベル以下でログに記録された診断を含めます。

数値表現列挙型メンバー名詳細レベルの説明
0None

情報なし

1Terse

最小限の情報

2Concise

中程度の情報量

3Detailed

ある程度の補足的な情報

4Verbose

多くの補足的な情報

既定では、プラグインは matlab.automation.Verbosity.Terse レベル (レベル 1) でログに記録された診断を含めます。診断ログを除外するには、LoggingLevelmatlab.automation.Verbosity.None (レベル 0) に指定します。

診断ログとは、log (TestCase) メソッドおよび log (Fixture) メソッドによってテスト フレームワークに送る診断です。

例: "LoggingLevel","detailed"

レポートするイベントの詳細レベル。0 ~ 4 の整数値、matlab.automation.Verbosity 列挙オブジェクト、事前定義された列挙メンバー名のいずれかに対応する string スカラーまたは文字ベクトルとして指定します。整数値は matlab.automation.Verbosity 列挙のメンバーに対応します。

プラグインは、パスしたイベント、失敗したイベント、およびログに記録されたイベントを、OutputDetail で指定された詳細レベルでレポートします。既定で、プラグインはイベントを matlab.automation.Verbosity.Detailed レベル (レベル 3) で記録します。

数値表現列挙型メンバー名詳細レベルの説明
0None

情報なし

1Terse

最小限の情報

2Concise

中程度の情報量

3Detailed

ある程度の補足的な情報

4Verbose

多くの補足的な情報

すべて展開する

作業フォルダーの新規ファイルに、以下のテスト クラスを含む ExampleTest.m を作成します。

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

コマンド プロンプトで ExampleTest クラスからテスト スイートを作成します。

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

suite = TestSuite.fromClass(?ExampleTest);

既定のプラグインを使用して、出力をコマンド ウィンドウに表示するテスト ランナーを作成します。

runner = TestRunner.withTextOutput;

出力を MyTapOutput.tap ファイルに送信する TAPPlugin を作成します。

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

プラグインを TestRunner に追加して、スイートを実行します。

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

================================================================================
Verification failed in ExampleTest/testOne.
    ----------------
    Test Diagnostic:
    ----------------
    Testing 5==4
    ---------------------
    Framework Diagnostic:
    ---------------------
    verifyEqual failed.
    --> The numeric values are not equal using "isequaln".
    --> Failure table:
            Actual    Expected    Error    RelativeError
            ______    ________    _____    _____________
                                                        
              5          4          1          0.25     
    
    Actual Value:
         5
    Expected Value:
         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.

プラグインによって作成されたファイルを表示します。

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

標準出力への表示を指定された TAPPlugin を使用することもできます。ただし、標準出力に表示される他のテキスト (失敗したテストの情報など) がストリームに割り込むと、無効になる可能性があります。

バージョン履歴

R2016b で導入