Main Content

matlab.automation.diagnostics.DiagnosticResult Class

Namespace: matlab.automation.diagnostics

Result of diagnosed Diagnostic object

Renamed from matlab.unittest.diagnostics.DiagnosticResult in R2023a

Description

A matlab.automation.diagnostics.DiagnosticResult object contains the result of a diagnosed matlab.automation.diagnostics.Diagnostic object. Use DiagnosticResult objects to access diagnostic results instead of interacting directly with Diagnostic objects.

Only an automation framework, such as the unit testing framework, creates objects of this class. The testing framework assigns property values to a DiagnosticResult object from the property values of objects of the QualificationEventData, LoggedDiagnosticEventData, QualificationDiagnosticRecord, and LoggedDiagnosticRecord classes.

Properties

expand all

Artifacts produced during the latest diagnostic evaluation, returned as a row vector of artifacts. After the framework diagnoses a Diagnostic object, it copies the value of the Artifacts property of that Diagnostic object into the Artifacts property of the corresponding DiagnosticResult object.

Attributes:

GetAccess
public
SetAccess
private

Diagnostic information, returned as a character vector. After the framework diagnoses a Diagnostic object, it copies the value of the DiagnosticText property of that Diagnostic object into the DiagnosticText property of the corresponding DiagnosticText object.

Attributes:

GetAccess
public
SetAccess
private

Examples

collapse all

In a file named FigurePropertiesTest.m in your current folder, create the FigurePropertiesTest test class. The failingTest method of the test class, which intentionally fails, uses a FigureDiagnostic object to save the figure so you can examine it later.

classdef FigurePropertiesTest < matlab.unittest.TestCase
    properties
        TestFigure
    end

    methods (TestMethodSetup)
        function createFigure(testCase)
            testCase.TestFigure = figure;
            testCase.addTeardown(@close,testCase.TestFigure)
        end
    end

    methods (Test)
        function defaultCurrentPoint(testCase)
            cp = testCase.TestFigure.CurrentPoint;
            testCase.verifyEqual(cp,[0 0], ...
                "Default current point must be [0 0].")
        end

        function defaultCurrentObject(testCase)
            import matlab.unittest.constraints.IsEmpty
            co = testCase.TestFigure.CurrentObject;
            testCase.verifyThat(co,IsEmpty, ...
                "Default current object must 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

Import the classes used in this example.

import matlab.unittest.plugins.DiagnosticsRecordingPlugin
import matlab.unittest.plugins.TestReportPlugin

Create a test suite from the test class.

suite = testsuite("FigurePropertiesTest");

Create a test runner that records diagnostics and generates a PDF test report.

runner = testrunner("minimal");
runner.addPlugin(DiagnosticsRecordingPlugin)
runner.addPlugin(TestReportPlugin.producingPDF("report.pdf"))

Set the ArtifactsRootFolder property of the test runner so that the framework saves any diagnostic artifacts produced during the test run to your current folder.

runner.ArtifactsRootFolder = pwd;

Run the tests in the test suite. One of the tests fails.

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:\work\report.pdf

results = 

  1×3 TestResult array with properties:

    Name
    Passed
    Failed
    Incomplete
    Duration
    Details

Totals:
   2 Passed, 1 Failed (rerun), 0 Incomplete.
   1.6241 seconds testing time.

Display the diagnostic result for the failed test. The returned DiagnosticResult object indicates that the framework saved two artifacts related to the third test. By default, a FigureDiagnostic object results in both a FIG file and a PNG file.

results(3).Details.DiagnosticRecord.TestDiagnosticResults
ans = 

  DiagnosticResult with properties:

         Artifacts: [1×2 matlab.automation.diagnostics.FileArtifact]
    DiagnosticText: 'Figure saved to:↵--> C:\Users\username\AppData\Local\Temp\817b4071-9d9d-471e-bead-eb0f93a89f1b\Figure_c79a5df0-04fc-4ebc-9eb6-920b23feba40.fig↵--> C:\Users\username\AppData\Local\Temp\817b4071-9d9d-471e-bead-eb0f93a89f1b\Figure_c79a5df0-04fc-4ebc-9eb6-920b23feba40.png'

Display the location of the first artifact. To inspect the image related to the failed test, open the file at the location shown in the FullPath property. The generated PDF test report also includes the captured image and the artifact paths.

results(3).Details.DiagnosticRecord.TestDiagnosticResults.Artifacts(1)
ans = 

  FileArtifact with properties:

        Name: "Figure_c79a5df0-04fc-4ebc-9eb6-920b23feba40.fig"
    Location: "C:\Users\username\AppData\Local\Temp\817b4071-9d9d-471e-bead-eb0f93a89f1b"
    FullPath: "C:\Users\username\AppData\Local\Temp\817b4071-9d9d-471e-bead-eb0f93a89f1b\Figure_c79a5df0-04fc-4ebc-9eb6-920b23feba40.fig"

Version History

Introduced in R2017a

expand all