Main Content

matlab.automation.diagnostics.Diagnostic.join

Class: matlab.automation.diagnostics.Diagnostic
Namespace: matlab.automation.diagnostics

Combine multiple diagnostics

Description

example

diagnostics = matlab.automation.diagnostics.Diagnostic.join(value1,...,valueN) combines multiple pieces of diagnostic information into an array of matlab.automation.diagnostics.Diagnostic objects.

Input Arguments

expand all

Diagnostic information to combine, specified as a comma-separated list of values of any data type. For example, you can specify each value as a string array, function handle, or an array of matlab.automation.diagnostics.Diagnostic objects.

Example: "Some Text"

Example: "Some Text",@dir

Output Arguments

expand all

Combined diagnostics, returned as an array of matlab.automation.diagnostics.Diagnostic objects. Each array element corresponds to one of the values in value1,...,valueN:

  • If a value is an array of objects that derive from matlab.automation.diagnostics.Diagnostic, the method includes it in diagnostics unmodified.

  • If a value is a string or character array, the method converts it to a StringDiagnostic object and includes the object in diagnostics.

  • If a value is a function handle, the method converts it to a FunctionHandleDiagnostic object and includes the object in diagnostics.

  • If a value is of any other type, the method converts it to a DisplayDiagnostic object and includes the object in diagnostics.

Attributes

Statictrue

To learn about attributes of methods, see Method Attributes.

Examples

expand all

Combine two values into a Diagnostic vector, and then display the diagnostics when a test fails.

First, import the classes used in this example.

import matlab.unittest.TestCase
import matlab.automation.diagnostics.Diagnostic

Create a test case for interactive testing.

testCase = TestCase.forInteractiveUse;

Create a 1-by-2 Diagnostic vector by combining a string scalar and a datetime object that provides the date and time of a test.

value1 = "Values must be equal.";
value2 = datetime;
diagnostics = Diagnostic.join(value1,value2);

Display the diagnostic information upon a test failure. The output includes the diagnostics in the order they appear in diagnostics. In addition, the output includes the framework diagnostic relevant to the verifyEqual qualification method.

testCase.verifyEqual(1,2,diagnostics)
Verification failed.
    ----------------
    Test Diagnostic:
    ----------------
    Values must be equal.
    ----------------
    Test Diagnostic:
    ----------------
      datetime
    
       09-Mar-2023 11:47:23
    ---------------------
    Framework Diagnostic:
    ---------------------
    verifyEqual failed.
    --> The numeric values are not equal using "isequaln".
    --> Failure table:
            Actual    Expected    Error    RelativeError
            ______    ________    _____    _____________
                                                        
              1          2         -1          -0.5     
    
    Actual Value:
         1
    Expected Value:
         2

Tips

  • The join static method lets you combine values of any data type into a Diagnostic array. For example, if d1, d2, and d3 are arbitrary values, you can execute matlab.automation.diagnostics.Diagnostic.join(d1,d2,d3) to create a Diagnostic array. If at least one of the values is a matlab.automation.diagnostics.Diagnostic object, then you can combine the values using array concatenation instead. In this example, because d3 is a Diagnostic object, the testing framework converts d1 and d2 to diagnostics as well.

    import matlab.unittest.TestCase
    import matlab.automation.diagnostics.DisplayDiagnostic
    
    testCase = TestCase.forInteractiveUse;
    
    d1 = "Some Text";
    d2 = @dir;
    d3 = DisplayDiagnostic(datetime);
    
    testCase.verifyFail([d1 d2 d3])

Version History

Introduced in R2013a