Main Content

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

matlab.unittest.plugins.XMLPlugin クラス

名前空間: matlab.unittest.plugins

XML 形式でテスト結果を書き込むプラグイン

説明

XMLPlugin クラスは、XML 形式のファイルにテスト結果を書き込むプラグインを作成します。

構築

matlab.unittest.plugins.XMLPlugin.producingJUnitFormatメソッドを使用して XMLPlugin をインスタンス化します。

コピーのセマンティクス

ハンドル。コピー操作に対するハンドル クラスの影響については、オブジェクトのコピーを参照してください。

すべて折りたたむ

次のテスト クラスを含む 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 is filtered
            testCase.assumeTrue(false)
        end
    end
end

ExampleTest クラスからテスト スイートを作成します。サイレント テスト ランナーを作成します。

import matlab.unittest.TestRunner
import matlab.unittest.TestSuite
import matlab.unittest.plugins.XMLPlugin

suite = TestSuite.fromClass(?ExampleTest);
runner = TestRunner.withNoPlugins;

ファイル myTestResults.xml にテスト結果を書き込む XMLPlugin を作成します。

xmlFile = 'myTestResults.xml';
p = XMLPlugin.producingJUnitFormat(xmlFile);

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

runner.addPlugin(p)
results = runner.run(suite);
table(results)
ans =

  3×6 table

              Name               Passed    Failed    Incomplete    Duration      Details   
    _________________________    ______    ______    __________    ________    ____________

    {'ExampleTest/testOne'  }    false     true        false        0.26691    {1×1 struct}
    {'ExampleTest/testTwo'  }    true      false       false       0.010303    {1×1 struct}
    {'ExampleTest/testThree'}    false     false       true        0.069284    {1×1 struct}

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

disp(fileread(xmlFile))
<?xml version="1.0" encoding="utf-8"?>
<testsuites>
   <testsuite errors="0" failures="1" name="ExampleTest" skipped="1" tests="3" time="0.3465">
      <testcase classname="ExampleTest" name="testOne" time="0.26691">
         <failure type="VerificationFailure">Verification failed in ExampleTest/testOne.
    ----------------
    Test Diagnostic:
    ----------------
    Testing 5==4
    ---------------------
    Framework Diagnostic:
    ---------------------
    verifyEqual failed.
    --&gt; The numeric values are not equal using "isequaln".
    --&gt; 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</failure>
      </testcase>
      <testcase classname="ExampleTest" name="testTwo" time="0.010303"/>
      <testcase classname="ExampleTest" name="testThree" time="0.069284">
         <skipped>An assumption was not met in ExampleTest/testThree and it filtered the remainder of the test.
    ---------------------
    Framework Diagnostic:
    ---------------------
    assumeTrue failed.
    --&gt; The value must evaluate to "true".
    
    Actual Value:
      logical
    
       0
    ------------------
    Stack Information:
    ------------------
    In C:\work\ExampleTest.m (ExampleTest.testThree) at 10</skipped>
      </testcase>
   </testsuite>
</testsuites>

ヒント

  • テスト ファイルがスクリプト ベースまたは関数ベースのテストである場合、<testcase> 要素の classname 属性の値はテスト ファイルの名前です。

バージョン履歴

R2015b で導入

参考

外部の Web サイト