このページの翻訳は最新ではありません。ここをクリックして、英語の最新版を参照してください。
selectPassed
クラス: matlab.unittest.plugins.diagnosticrecord.DiagnosticRecord
パッケージ: matlab.unittest.plugins.diagnosticrecord
パスしたイベントの診断記録を返す
構文
selectedRecords = selectPassed(records)
説明
selectedRecords = selectPassed(
は、パスしたイベントの診断記録を records
)matlab.unittest.plugins.diagnosticrecord.QualificationDiagnosticRecord
インスタンスの配列として返します。
入力引数
records
— テスト結果の診断記録
matlab.unittest.plugins.diagnosticrecord.DiagnosticRecord
インスタンスの配列
テスト結果の診断記録。matlab.unittest.plugins.diagnosticrecord.DiagnosticRecord
インスタンスの配列として指定します。TestResult
の Details
プロパティの DiagnosticRecord
フィールドを介して診断記録にアクセスします。たとえば、テスト結果が変数 results
に格納されている場合、2 番目のテストの診断記録を検索するには records = result(2).Details.DiagnosticRecord
を呼び出します。
例
テスト結果の診断を選択
作業フォルダーに、以下のテスト クラスを含む ExampleTest.m
ファイルを作成します。このテストの目的は DiagnosticsRecordingPlugin
プラグインの使用方法を説明することであり、代表的なユニット テストを示すことではありません。
classdef ExampleTest < matlab.unittest.TestCase methods (Test) function testA(testCase) testCase.log(1,'Terse log message') % logs testCase.log(3,'Detailed log message') % logs testCase.verifyEqual(3+2,5) % passes testCase.assumeTrue(true) % passes testCase.verifyGreaterThan(5, 9) % fails testCase.assertEqual(3.14,pi) % fails/incomplete end function testB(testCase) % This test contains an intentional error - passing a character % instead of a variable to the ones function. a = [1 2]; testCase.verifyEqual(ones('a'),[1 1]); % errors end end end
コマンド プロンプトで ExampleTest
クラスからテスト スイートを作成します。
suite = testsuite('ExampleTest');
プラグインなしでテスト ランナーを作成します。このコードはメッセージを表示しないランナーを作成し、インストールされたプラグインの完全な制御を可能にします。テスト ランナーに DiagnosticsRecordingPlugin
を追加します。
import matlab.unittest.TestRunner; import matlab.unittest.plugins.DiagnosticsRecordingPlugin; runner = TestRunner.withNoPlugins; runner.addPlugin(DiagnosticsRecordingPlugin);
テストを実行します。
results = runner.run(suite);
2 番目のテストの結果を表示します。テストは失敗し完了しません。
results(2)
ans = TestResult with properties: Name: 'ExampleTest/testB' Passed: 0 Failed: 1 Incomplete: 1 Duration: 7.8912e-04 Details: [1×1 struct] Totals: 0 Passed, 1 Failed, 1 Incomplete. 0.00078912 seconds testing time.
診断記録のインデックスを指定して、さらに情報を表示します。
results(2).Details.DiagnosticRecord
ans = ExceptionDiagnosticRecord with properties: Event: 'ExceptionThrown' EventScope: TestMethod EventLocation: 'ExampleTest/testB' Exception: [1×1 MException] AdditionalDiagnosticResults: [1×0 matlab.unittest.diagnostics.DiagnosticResult] Stack: [1×1 struct] Report: 'Error occurred in ExampleTest/testB and it did not run to completion…'
テストはキャッチされていない例外をスローします。
最初のテスト testA
の診断記録を収集します。
testA_records = results(1).Details.DiagnosticRecord
testA_records = 1×3 heterogeneous DiagnosticRecord (LoggedDiagnosticRecord, QualificationDiagnosticRecord) array with properties: Event EventScope EventLocation Stack Report
testA
についてプラグインが記録したイベントを表示します。
{testA_records.Event}'
ans = 3×1 cell array {'DiagnosticLogged' } {'VerificationFailed'} {'AssertionFailed' }
このプラグインは詳細レベル Terse
でログが作成されたメッセージと、検証エラーおよびアサーション エラーを記録します。
すべての詳細レベルのメッセージを記録し、パスした診断を含めるプラグインを作成します。テストを再実行し、testA
の診断記録を収集します。
runner = TestRunner.withNoPlugins; runner.addPlugin(DiagnosticsRecordingPlugin(... 'IncludingPassingDiagnostics',true,'OutputDetail',4,'LoggingLevel',4)); results = runner.run(suite); testA_records = results(1).Details.DiagnosticRecord;
testA
についてプラグインが記録したイベントを表示します。
{testA_records.Event}'
ans = 6×1 cell array {'DiagnosticLogged' } {'DiagnosticLogged' } {'VerificationPassed'} {'AssumptionPassed' } {'VerificationFailed'} {'AssertionFailed' }
このプラグインは、すべての検定と log
メソッドの呼び出しに関する診断情報を記録します。
失敗したイベントの診断記録をすべて選択します。
failedRecords = selectFailed(testA_records)
failedRecords = 1×2 QualificationDiagnosticRecord array with properties: Event EventScope EventLocation TestDiagnosticResults FrameworkDiagnosticResults AdditionalDiagnosticResults Stack Report
パスしたイベントの診断記録をすべて選択し、1 番目の記録のレポートを表示します。
passedRecords = selectPassed(testA_records); passedRecords(1).Report
ans = 'Verification passed in ExampleTest/testA. --------------------- Framework Diagnostic: --------------------- verifyEqual passed. --> The values are equal using "isequaln". Actual Value: 5 Expected Value: 5 ------------------ Stack Information: ------------------ In C:\work\ExampleTest.m (ExampleTest.testA) at 6'
未完了イベントの記録をすべて選択します。
incompleteRecords = selectIncomplete(testA_records)
incompleteRecords = QualificationDiagnosticRecord with properties: Event: 'AssertionFailed' EventScope: TestMethod EventLocation: 'ExampleTest/testA' TestDiagnosticResults: [1×0 matlab.unittest.diagnostics.DiagnosticResult] FrameworkDiagnosticResults: [1×1 matlab.unittest.diagnostics.DiagnosticResult] AdditionalDiagnosticResults: [1×0 matlab.unittest.diagnostics.DiagnosticResult] Stack: [1×1 struct] Report: 'Assertion failed in ExampleTest/testA and it did not run to completion…'
このイベントはアサーション エラーであるため、フレームワークはこの失敗の診断記録を failedRecords(2)
でも返します。
ログが作成されたイベントをもつ記録すべてを選択して、ログが作成されたメッセージを表示します。
loggedRecords = selectLogged(testA_records); {loggedRecords.Report}'
ans = 2×1 cell array {'[Terse] Diagnostic logged (2018-04-12 13:15:23): Terse log message' } {'[Detailed] Diagnostic logged (2018-04-12 13:15:23): Detailed log message'}
バージョン履歴
R2016a で導入
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)