log
クラス: matlab.unittest.fixtures.Fixture
パッケージ: matlab.unittest.fixtures
フィクスチャのセットアップと破棄の処理中に診断情報を記録する
構文
log(f,diagnostic)
log(f,v,diagnostic)
説明
log(
は指定した診断情報を記録します。log メソッドは、フィクスチャのセットアップおよび破棄ルーチンの最中にテストの情報を記録する手段を提供します。テスト フレームワークでは、f
,diagnostic
)matlab.unittest.plugins.LoggingPlugin
などの適切なプラグインを追加してテスト フレームワークの動作を構成した場合に限り、記録したメッセージが表示されます。
log(
は指定した詳細レベル f
,v
,diagnostic
)v
で診断情報を記録します。
入力引数
f
— フィクスチャのインスタンス
matlab.unittest.fixtures.Fixture
インスタンス
フィクスチャのインスタンス。matlab.unittest.fixtures.Fixture
として指定します。
diagnostic
— 失敗時に表示する診断情報
string | 文字ベクトル | 関数ハンドル | matlab.automation.diagnostics.Diagnostic
インスタンス
失敗時に表示する診断情報。string、文字ベクトル、関数ハンドル、または matlab.automation.diagnostics.Diagnostic
インスタンスとして指定します。
v
— 詳細レベル
2
(既定値) | 1
| 3
| 4
| matlab.automation.Verbosity
列挙
詳細レベル。1 ~ 4 の整数値または matlab.automation.Verbosity
列挙オブジェクトとして指定します。診断メッセージの既定の詳細レベルは Concise
です。整数値は matlab.automation.Verbosity
列挙のメンバーに対応します。
数値表現 | 列挙型メンバー名 | 詳細レベルの説明 |
---|---|---|
1 | Terse | 最小限の情報 |
2 | Concise | 中程度の情報量 |
3 | Detailed | ある程度の補足的な情報 |
4 | Verbose | 多くの補足的な情報 |
例
診断情報の記録
現在の作業フォルダーのファイル FormatHexFixture.m
の中で、次のフィクスチャを作成します。
classdef FormatHexFixture < matlab.unittest.fixtures.Fixture properties (Access=private) OriginalFormat end methods function setup(fixture) fixture.OriginalFormat = format().NumericFormat; fixture.log(['The previous format setting was ',... fixture.OriginalFormat]) log(fixture,'Setting Format') format('hex') log(fixture,3,'Format Set') end function teardown(fixture) log(fixture,'Resetting Format') format(fixture.OriginalFormat) log(fixture,3,'Original Format Restored') end end end
現在の作業フォルダーのファイル SampleTest.m
の中で、次のテスト クラスを作成します。
classdef SampleTest < matlab.unittest.TestCase methods (Test) function test1(testCase) testCase.applyFixture(FormatHexFixture); actStr = getColumnForDisplay([1;2;3], 'Small Integers'); expStr = ['Small Integers ' '3ff0000000000000' '4000000000000000' '4008000000000000']; testCase.verifyEqual(actStr, expStr) end end end function str = getColumnForDisplay(values, title) elements = cell(numel(values)+1, 1); elements{1} = title; for idx = 1:numel(values) elements{idx+1} = displayNumber(values(idx)); end str = char(elements); end function str = displayNumber(n) str = strtrim(evalc('disp(n);')); end
テストを実行します。
result = run(SampleTest);
Running SampleTest . Done SampleTest __________
既定のテスト ランナーの詳細レベルは 1 (Terse
)であり、既定のログ メッセージはレベル 2 (Concise
) であるため、記録されたメッセージは何も表示されません。
レベル 1、2 および 3 の診断情報を報告するテスト ランナーを作成し、テストを再度実行します。
import matlab.unittest.TestRunner import matlab.unittest.plugins.LoggingPlugin ts = matlab.unittest.TestSuite.fromClass(?SampleTest); runner = TestRunner.withNoPlugins; p = LoggingPlugin.withVerbosity(3); runner.addPlugin(p); results = runner.run(ts);
[Concise] Diagnostic logged (2022-09-30T15:36:46): The previous format setting was short [Concise] Diagnostic logged (2022-09-30T15:36:46): Setting Format [Detailed] Diagnostic logged (2022-09-30T15:36:46): Format Set [Concise] Diagnostic logged (2022-09-30T15:36:47): Resetting Format [Detailed] Diagnostic logged (2022-09-30T15:36:47): Original Format Restored
バージョン履歴
R2014b で導入
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)