メインコンテンツ

matlab.unittest.plugins.XMLPlugin.producingJUnitFormat

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

テスト結果を JUnit スタイルの XML 形式で出力するプラグインを作成

説明

plugin = matlab.unittest.plugins.XMLPlugin.producingJUnitFormat(filename) は、指定されたファイルに JUnit スタイルの XML 形式でテスト結果を書き込むプラグインを作成します。

このプラグインを使用すると、MATLAB® ユニット テストの結果を、JUnit スタイルの XML 形式を認識するサードパーティ システムに統合することが可能になります。たとえば、テスト結果を Jenkins®、TeamCity®、Azure® DevOps などの継続的インテグレーション プラットフォームに統合することができます。

plugin = matlab.unittest.plugins.XMLPlugin.producingJUnitFormat(filename,"OutputDetail",level) は、失敗したイベントの指定されたレベルの詳細を含めるプラグインを作成します。

入力引数

すべて展開する

テスト結果を格納するファイルの名前。.xml で終わる string スカラーまたは文字ベクトルとして指定します。値は現在のフォルダーに対する相対パスまたは絶対パスのいずれかになります。ファイルが存在する場合、プラグインはその内容を上書きします。

例: "results.xml"

例: "C:\work\results.xml"

失敗したイベントの詳細を含めるレベル。0 から 4 までの整数スカラー、matlab.automation.Verbosity 列挙オブジェクト、または列挙のテキスト表現として指定します。既定では、プラグインは失敗したイベントの matlab.automation.Verbosity.Detailed レベル (レベル 3) の詳細を含めます。

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

情報なし

1Terse

最小限の情報

2Concise

中程度の情報量

3Detailed

ある程度の補足的な情報

4Verbose

多くの補足的な情報

例: plugin = matlab.unittest.plugins.XMLPlugin.producingJUnitFormat("myResults.xml","OutputDetail","verbose") は、失敗したイベントの matlab.automation.Verbosity.Verbose レベルの詳細を含めるプラグインを作成します。

属性

Statictrue

メソッドの属性の詳細については、メソッドの属性を参照してください。

すべて展開する

XMLPlugin クラスを使用して、テスト結果を JUnit スタイルの XML 形式で出力します。

現在のフォルダーに、sampleTest.m という名前の関数ベースのテスト ファイルを作成します。ファイルには、パスするテストが 2 つと失敗するテストが 1 つ含まれています。

function tests = sampleTest
tests = functiontests(localfunctions);
end

function testA(testCase)      % Test passes
verifyEqual(testCase,2+3,5)
end

function testB(testCase)      % Test fails
verifyGreaterThan(testCase,13,42)
end

function testC(testCase)      % Test passes
verifySubstring(testCase,"Hello World!","llo")
end

XMLPlugin クラスをインポートします。

import matlab.unittest.plugins.XMLPlugin

テスト結果を JUnit スタイルの XML 形式で出力するプラグインでテスト ランナーを作成します。プラグインの作成には producingJUnitFormat 静的メソッドを使用します。

runner = testrunner("minimal");
filename = "results.xml";
plugin = XMLPlugin.producingJUnitFormat(filename);
addPlugin(runner,plugin)

テスト ファイルからテスト スイートを作成し、テストを実行します。テスト ランナーでテストが実行され、プラグインにより、現在のフォルダー内の results.xml という名前のファイルにテスト結果が保存されます。

suite = testsuite("sampleTest.m");
run(runner,suite);

生成されたテスト アーティファクトの内容を表示します。ファイル内の結果は、testAtestC はパスしたが testB は検証エラーで失敗したことを示しています。

disp(fileread(filename))
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<testsuites>
  <testsuite errors="0" failures="1" name="sampleTest" skipped="0" tests="3" time="1.3417">
    <testcase classname="sampleTest" name="testA" time="0.38058"/>
    <testcase classname="sampleTest" name="testB" time="0.92769">
      <failure type="VerificationFailure">Verification failed in sampleTest/testB.
    ---------------------
    Framework Diagnostic:
    ---------------------
    verifyGreaterThan failed.
    --&gt; The value must be greater than the minimum value.
    
    Actual Value:
        13
    Minimum Value (Exclusive):
        42
    ------------------
    Stack Information:
    ------------------
    In C:\work\sampleTest.m (testB) at 10</failure>
    </testcase>
    <testcase classname="sampleTest" name="testC" time="0.033431"/>
  </testsuite>
</testsuites>

ヒント

  • スクリプト ベースまたは関数ベースのテストについては、結果の XML ファイル内の <testcase> 要素の classname 属性の値がテスト ファイルの名前になります。

バージョン履歴

R2015b で導入