matlab.unittest.diagnostics.FigureDiagnostic Class
Namespace: matlab.unittest.diagnostics
Diagnostic to save specified figure
Description
Use the FigureDiagnostic
class to create a diagnostic that saves a figure to a
file. The file persists after MATLAB® completes the test run, and so it is available for post-test inspection.
Construction
FigureDiagnostic(
creates
a diagnostic to save a specified figure. When the testing framework
diagnoses the fig
)FigureDiagnostic
instance, it saves fig
to
a FIG file and to a PNG file. Each file has a unique name consisting
of a prefix ('Figure_'
, by default), an automatically
generated identifier, and the file extension. An example file name
is Figure_cf95fe7f-5a7c-4310-9c19-16c0c17a969f.png
.
To view the location of the file, access the FileArtifact
object
through the TestResult
instance.
FigureDiagnostic(
creates
a diagnostic with additional options specified by one or more fig
,Name,Value
)Name,Value
pair
arguments. You can specify several name-value pair arguments in any
order as Name1,Value1,...,NameN,ValueN
. For example, FigureDiagnostic(fig,'Prefix','LoggedFigure_','Formats','png')
saves fig
as
a PNG file only, and uses the prefix 'LoggedFigure_'
instead
of 'Figure_'
.
Input Arguments
Properties
Copy Semantics
Handle. To learn how handle classes affect copy operations, see Copying Objects.
Examples
Tips
The location of the saved figure is a folder with a name unique to a test run within the folder contained in the
ArtifactsRootFolder
. If you are running a test without aTestRunner
, for example withmatlab.unittest.TestCase.forInteractiveUse
, the root folder is the value returned bytempdir()
.To determine the path of the saved figure, access the
FileArtifact
object for a particular test result. For example, assume thatres
is aTestResult
array. Determine the location of the saved figure for the first element of the array as follows.res(1).Details.DiagnosticRecord.TestDiagnosticResults.Artifacts
ans = FileArtifact with properties: Name: "Figure_3984704d-b884-44c2-b3ee-7ed10d36e967.png" Location: "C:\mywork\Temp\a1f80242-8f8a-4678-9124-415980432d08" FullPath: "C:\mywork\Temp\a1f80242-8f8a-4678-9124-415980432d08\Figure_3984704d-b884-44c2-b3ee-7ed10d36e967.png"
Version History
Introduced in R2017a