Main Content

log

Class: matlab.unittest.TestCase
Namespace: matlab.unittest

Record diagnostic information during test execution

Syntax

log(testCase,diagnostic)
log(testCase,v,diagnostic)

Description

log(testCase,diagnostic) logs the supplied diagnostic. The log method provides a means for tests to log information during their execution. The testing framework displays logged messages only if you configure it to do so by adding an appropriate plugin, such as the matlab.unittest.plugins.LoggingPlugin.

log(testCase,v,diagnostic) logs the diagnostic at the specified verbosity level, v.

Input Arguments

expand all

Instance of test case, specified as a matlab.unittest.TestCase.

Diagnostic information to display upon a failure, specified as a string array, character array, function handle, or matlab.automation.diagnostics.Diagnostic instance.

Verbosity level, specified as an integer value between 1 and 4, a matlab.automation.Verbosity enumeration object, or a string scalar or character vector corresponding to one of the predefined enumeration member names. The default verbosity level for diagnostic messages is Concise. Integer values correspond to the members of the matlab.automation.Verbosity enumeration.

Numeric RepresentationEnumeration Member NameVerbosity Description
1Terse

Minimal information

2Concise

Moderate amount of information

3Detailed

Some supplemental information

4Verbose

Lots of supplemental information

Examples

expand all

Create a function-based test in a file, sampleLogTest.m, in your working folder.

function tests = sampleLogTest
tests = functiontests(localfunctions);

function svdTest(testCase)
import matlab.automation.Verbosity

log(testCase,'Generating matrix.')
m = rand(1000);

log(testCase,1,'About to call SVD.')
[U,S,V] = svd(m);

log(testCase,Verbosity.Terse,'SVD finished.')

verifyEqual(testCase,U*S*V',m,'AbsTol',1e-6)

At the command prompt, run the test.

results = run(sampleLogTest);
Running sampleLogTest

[Terse] Diagnostic logged (2022-10-15 18:35:02): About to call SVD.

[Terse] Diagnostic logged (2022-10-15 18:35:20): SVD finished.
.
Done sampleLogTest
__________

The default runner reports the diagnostics at level 1 (Terse).

Create a test runner to report the diagnostics at levels 1 and 2, and rerun the test.

import matlab.unittest.TestRunner
import matlab.unittest.plugins.LoggingPlugin

runner = TestRunner.withNoPlugins;
p = LoggingPlugin.withVerbosity(2);
runner.addPlugin(p)

results = runner.run(sampleLogTest);
 [Concise] Diagnostic logged (2022-10-15T18:36:05): Generating matrix.
   [Terse] Diagnostic logged (2022-10-15T18:36:05): About to call SVD.
   [Terse] Diagnostic logged (2022-10-15T18:36:05): SVD finished.

Version History

Introduced in R2014b