メインコンテンツ

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

matlab.unittest.plugins.TestRunProgressPlugin クラス

R2024b

名前空間: matlab.unittest.plugins

テスト実行の進行状況を報告するプラグイン

説明

TestRunProgressPlugin クラスはテスト実行の進行状況を報告するプラグインを作成します。

構築

matlab.unittest.plugins.TestRunProgressPlugin.withVerbosity(v) は指定した詳細レベルの TestRunProgressPlugin を生成します。

matlab.unittest.plugins.TestRunProgressPlugin.withVerbosity(v,stream) は、テキスト出力を出力ストリームにリダイレクトします。

入力引数

すべて展開する

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

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

情報なし

1Terse

最小限の情報

2Concise

中程度の情報量

3Detailed

ある程度の補足的な情報

4Verbose

多くの補足的な情報

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

コピーのセマンティクス

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

例

すべて折りたたむ

作業フォルダー内のファイルに cylinderPlotTest という名前の関数ベースのテストを作成します。

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

コマンド プロンプトで、テストを実行します。

results = run(cylinderPlotTest);
Running cylinderPlotTest
..
Done cylinderPlotTest
__________

既定では、テスト ランナーは詳細レベル 2 を使用します。

レベル 1 の診断情報を報告するテスト ランナーを作成し、テストを再度実行します。

import matlab.unittest.TestRunner
import matlab.unittest.plugins.TestRunProgressPlugin

runner = TestRunner.withNoPlugins;
p = TestRunProgressPlugin.withVerbosity(1);
runner.addPlugin(p);

results = runner.run(cylinderPlotTest);
..

レベル 4 の診断情報を報告するテスト ランナーを作成し、テストを再度実行します。

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
__________

現在の作業フォルダー内のファイルで ExampleProgressTest という名前のクラスを作成します。

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

コマンド プロンプトでテスト スイートと詳細レベル 3 のランナーを作成し、テストを実行します。

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
__________

myOutput.log という名前のファイルに出力を行う新しいプラグインを作成し、テストを再度実行します。

import matlab.automation.streams.ToFile
outFile = 'myOutput.log';

runner = TestRunner.withNoPlugins;
p = TestRunProgressPlugin.withVerbosity(3,ToFile(outFile));
runner.addPlugin(p)

results = runner.run(suite);

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

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
__________

バージョン履歴

R2014b で導入