matlab.unittest.plugins.TestReportPlugin クラス
名前空間: matlab.unittest.plugins
スーパークラス: matlab.unittest.plugins.TestRunnerPlugin, matlab.unittest.plugins.Parallelizable
テスト レポートを生成するプラグイン
説明
作成
TestReportPlugin の静的メソッドのいずれかを使用してそのインスタンスを作成します。
DOCX テスト レポートを生成するプラグインを作成するには、静的メソッド
producingDOCXを使用します。HTML テスト レポートを生成するプラグインを作成するには、静的メソッド
producingHTMLを使用します。PDF テスト レポートを生成するプラグインを作成するには、静的メソッド
producingPDFを使用します。
プロパティ
テスト レポートのタイトル。string スカラーとして返されます。このプロパティの値は、プラグインの作成時に指定できます。既定では、プラグインは "MATLAB® Test Report" をタイトルとして使用します。
属性:
GetAccess | public |
SetAccess | immutable |
コマンド ウィンドウからのテキスト出力を含めるかどうか。データ型 logical の 0 または 1 として返されます。このプロパティの値は、プラグインの作成時に指定できます。既定では、プラグインはコマンド ウィンドウからのテキスト出力をテスト レポートに含めません。
属性:
GetAccess | public |
SetAccess | immutable |
パスしたイベントの診断情報を含めるかどうか。データ型 logical の 0 または 1 として返されます。このプロパティの値は、プラグインの作成時に指定できます。既定では、プラグインはパスしたイベントの診断情報をテスト レポートに含めません。
属性:
GetAccess | public |
SetAccess | immutable |
テスト レポートに含める診断ログの最大詳細レベル。matlab.automation.Verbosity 列挙オブジェクトとして返されます。このプロパティの値は、プラグインの作成時に指定できます。既定では、プラグインは matlab.automation.Verbosity.Terse レベルでログに記録された診断情報を含めます。
診断ログとは、log (TestCase) メソッドおよび log (Fixture) メソッドによってテスト フレームワークに送る診断です。
属性:
GetAccess | public |
SetAccess | private |
メソッド
matlab.unittest.plugins.TestReportPlugin.producingDOCX | DOCX テスト レポートを生成するプラグインを作成する |
matlab.unittest.plugins.TestReportPlugin.producingHTML | HTML テスト レポートを生成するプラグインを作成する |
matlab.unittest.plugins.TestReportPlugin.producingPDF | PDF テスト レポートを生成するプラグインを作成する |
例
2 つのテスト ファイルからテスト スイートを作成し、スイートを実行して、結果の .docx レポートを生成します。
ScriptBasedTest.m という名前の作業フォルダーに、以下のテスト スクリプトを含む新しいファイルを作成します。スクリプトには 2 つの失敗する未完了のテストが含まれます。
%% Test double class expSolution = 'double'; actSolution = ones; assert(isa(actSolution,expSolution)) %% Test single class expSolution = 'single'; actSolution = ones('single'); assert(isa(actSolution,expSolution)) %% Test uint16 class expSolution = 'uint16'; actSolution = ones('uint16'); assert(isa(actSolution,expSolution)) %% Test that fails assert(false==true); %% Another test that fails assert(strcmp('correlation','causation'))
以下のテスト クラスを含む ClassBasedTest.m という名前のファイルを作成します。
classdef ClassBasedTest < matlab.unittest.TestCase properties (ClassSetupParameter) generator = {'twister','combRecursive','multFibonacci'}; end properties (MethodSetupParameter) seed = {0,123,4294967295}; end properties (TestParameter) dim1 = struct('small',1,'medium',2,'large',3); dim2 = struct('small',2,'medium',3,'large',4); dim3 = struct('small',3,'medium',4,'large',5); type = {'single','double'}; end methods (TestClassSetup) function ClassSetup(testCase,generator) orig = rng; testCase.addTeardown(@rng,orig) rng(0, generator) end end methods (TestMethodSetup) function MethodSetup(testCase,seed) orig = rng; testCase.addTeardown(@rng,orig) rng(seed) end end methods (Test, ParameterCombination='sequential') function testSize(testCase,dim1,dim2,dim3) testCase.verifySize(rand(dim1,dim2,dim3),[dim1 dim2 dim3]) end end methods (Test, ParameterCombination='pairwise') function testRepeatable(testCase,dim1,dim2,dim3) state = rng; firstRun = rand(dim1,dim2,dim3); rng(state) secondRun = rand(dim1,dim2,dim3); testCase.verifyEqual(firstRun,secondRun); end end methods (Test) function testClass(testCase,dim1,dim2,type) testCase.verifyClass(rand(dim1,dim2,type),type) end end end
コマンド プロンプトで、両方のテスト ファイルからテスト スイートを作成します。
import matlab.unittest.TestRunner; import matlab.unittest.TestSuite; import matlab.unittest.plugins.TestReportPlugin; suite = testsuite({'ScriptBasedTest','ClassBasedTest'})
suite =
1×284 Test array with properties:
Name
ProcedureName
TestClass
BaseFolder
Parameterization
SharedTestFixtures
Tags
Tests Include:
17 Unique Parameterizations, 0 Shared Test Fixture Classes, 0 Tags.サイレント テスト ランナーを作成し、コマンド ウィンドウに情報が出力されないようにします。出力を MyTestReport.docx ファイルに送信する TestReportPlugin を作成します。
runner = TestRunner.withNoPlugins;
docxFile = 'MyTestReport.docx';
plugin = TestReportPlugin.producingDOCX(docxFile);プラグインを TestRunner に追加して、スイートを実行します。
runner.addPlugin(plugin); result = runner.run(suite)
Generating report. Please wait.
Preparing content for the report.
Adding content to the report.
Writing report to file.
Report has been saved to: C:\work\MyTestReport.docx
result =
1×284 TestResult array with properties:
Name
Passed
Failed
Incomplete
Duration
Details
Totals:
282 Passed, 2 Failed, 2 Incomplete.
0.73477 seconds testing time.テスト レポートを開きます。
open(docxFile)
関数ベースのテストからテスト スイートを作成し、スイートを実行して、結果のレポートを生成します。パスした診断情報とコマンド ウィンドウへのテキスト出力を含めます。
FunctionBasedTest.m という名前の作業フォルダーに、以下の関数ベースのテストを含む新しいファイルを作成します。テスト ファイルには 2 つの失敗するテストが含まれます。
%% Main function to generate tests function tests = FunctionBasedTest tests = functiontests(localfunctions); end %% Test Functions function passingTest(testCase) actSolution = 13*3+7*5; expSolution = 74; verifyEqual(testCase,actSolution,expSolution) end function failingTest(testCase) actSolution = single(1); verifyTrue(testCase,actSolution) end function anotherPassingTest(testCase) verifyClass(testCase,string('some text'),'string') end function anotherFailingTest(testCase) verifyTrue(testCase,strcmp('42','everything')) end
コマンド プロンプトで、FunctionBasedTest.m からテスト スイートを作成します。既定のプラグインを使用して、出力をコマンド ウィンドウに表示するテスト ランナーを作成します。
import matlab.unittest.TestRunner; import matlab.unittest.TestSuite; import matlab.unittest.plugins.TestReportPlugin; suite = testsuite('FunctionBasedTest'); runner = TestRunner.withTextOutput;
出力を MyTestReport2.pdf ファイルに送信する TestReportPlugin を作成します。パスした診断情報とコマンド ウィンドウのテキスト出力をレポートに含めます。
pdfFile = 'MyTestReport2.pdf'; plugin = TestReportPlugin.producingPDF(pdfFile,... 'IncludingPassingDiagnostics',true,'IncludingCommandWindowText',true);
プラグインを TestRunner に追加して、スイートを実行します。
runner.addPlugin(plugin); result = runner.run(suite);
Running FunctionBasedTest
.
================================================================================
Verification failed in FunctionBasedTest/failingTest.
---------------------
Framework Diagnostic:
---------------------
verifyTrue failed.
--> The value must be logical. It is of type "single".
Actual single:
1
------------------
Stack Information:
------------------
In C:\Work\FunctionBasedTest.m (failingTest) at 15
================================================================================
..
================================================================================
Verification failed in FunctionBasedTest/anotherFailingTest.
---------------------
Framework Diagnostic:
---------------------
verifyTrue failed.
--> The value must evaluate to "true".
Actual logical:
0
------------------
Stack Information:
------------------
In C:\Work\FunctionBasedTest.m (anotherFailingTest) at 23
================================================================================
.
Done FunctionBasedTest
__________
Failure Summary:
Name Failed Incomplete Reason(s)
===================================================================================
FunctionBasedTest/failingTest X Failed by verification.
-----------------------------------------------------------------------------------
FunctionBasedTest/anotherFailingTest X Failed by verification.
Generating report. Please wait.
Preparing content for the report.
Adding content to the report.
Writing report to file.
Report has been saved to: C:\Work\MyTestReport2.pdfテスト レポートを開きます。
open(pdfFile)
現在の作業フォルダーのファイル内に、FigurePropTest テスト クラスを作成します。failingTest テスト メソッドは、失敗した場合 (この例では常に失敗する) に、後で確認できるように FigureDiagnostic を使用して Figure を保存します。
classdef FigurePropTest < matlab.unittest.TestCase properties TestFigure end methods (TestMethodSetup) function createFigure(testCase) testCase.TestFigure = figure; end end methods (TestMethodTeardown) function closeFigure(testCase) close(testCase.TestFigure) end end methods (Test) function defaultCurrentPoint(testCase) cp = testCase.TestFigure.CurrentPoint; testCase.verifyEqual(cp,[0 0], ... 'Default current point is incorrect') end function defaultCurrentObject(testCase) import matlab.unittest.constraints.IsEmpty co = testCase.TestFigure.CurrentObject; testCase.verifyThat(co,IsEmpty, ... 'Default current object should be empty') end function failingTest(testCase) import matlab.unittest.diagnostics.FigureDiagnostic fig = testCase.TestFigure; ax = axes(fig); surf(ax,peaks) testCase.verifyEmpty(testCase.TestFigure.Children, ... FigureDiagnostic(testCase.TestFigure)) end end end
コマンド プロンプトでテスト スイートを作成します。
suite = testsuite('FigurePropTest');診断を記録して PDF レポートを生成するサイレント テスト ランナーを作成します。
import matlab.unittest.plugins.DiagnosticsRecordingPlugin import matlab.unittest.plugins.TestReportPlugin runner = matlab.unittest.TestRunner.withNoPlugins; runner.addPlugin(DiagnosticsRecordingPlugin) runner.addPlugin(TestReportPlugin.producingPDF('MyTestReport.pdf'))
既定のアーティファクトのルートを現在の作業フォルダーに変更します。
runner.ArtifactsRootFolder = pwd;
テストを実行します。3 番目のテストは失敗します。
results = runner.run(suite)
Generating test report. Please wait.
Preparing content for the test report.
Adding content to the test report.
Writing test report to file.
Test report has been saved to:
C:\wok\MyTestReport.pdf
results =
1×3 TestResult array with properties:
Name
Passed
Failed
Incomplete
Duration
Details
Totals:
2 Passed, 1 Failed (rerun), 0 Incomplete.
8.3355 seconds testing time.3 番目のテストの診断結果を表示します。テスト フレームワークは、3 番目のテストに関連する 2 つのアーティファクトを保存しました。FigureDiagnostic オブジェクトは、既定で Figure を PNG ファイルと FIG ファイルの両方として保存します。
results(3).Details.DiagnosticRecord.TestDiagnosticResults
ans =
DiagnosticResult with properties:
Artifacts: [1×2 matlab.automation.diagnostics.FileArtifact]
DiagnosticText: 'Figure saved to:↵--> C:\work\530aa31c-86c7-4712-a064-d9f00ce041fb\Figure_dfd8c611-8387-4579-804f-6384642ba4ff.fig↵--> C:\work\530aa31c-86c7-4712-a064-d9f00ce041fb\Figure_dfd8c611-8387-4579-804f-6384642ba4ff.png'
最初のアーティファクトの保存場所を表示します。
results(3).Details.DiagnosticRecord.TestDiagnosticResults.Artifacts(1)
ans =
FileArtifact with properties:
Name: "Figure_dfd8c611-8387-4579-804f-6384642ba4ff.fig"
Location: "C:\work\530aa31c-86c7-4712-a064-d9f00ce041fb"
FullPath: "C:\work\530aa31c-86c7-4712-a064-d9f00ce041fb\Figure_dfd8c611-8387-4579-804f-6384642ba4ff.fig"
失敗したテストに関連するイメージを検査するには、FullPath フィールドに示された場所にあるファイルを開きます。さらに、PDF のテスト レポートを生成しているため、イメージは MyTestReport.pdf に取得されています。テスト レポートには、アーティファクトへのパスも記載されています。
バージョン履歴
R2016b で導入テスト レポートのタイトルの変更をサポートするために、TestReportPlugin クラスに Title という名前の新しいプロパティが追加されました。
TestReportPlugin クラスを使用して生成されたテスト レポートには、タグ付けされたテスト スイート要素のテスト タグが表示されます。タグ付けされたテスト レポートは、DOCX、HTML、および PDF の形式で生成できます。
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)