Main Content

padv.util.openTestCase

Open test case artifact

    Description

    status = padv.util.openTestCase(artifact) opens the test case artifact in Test Manager.

    example

    status = padv.util.openTestCase(artifact,loadTestResults) opens the test case artifact in Test Manager and attempts to load the test results for the test case if loadTestResults is true.

    You can use this function inside the openArtifact method of a task to customize how Process Advisor opens test case artifacts in the I/O column. For an example, open the built-in task padv.builtin.task.RunTestsPerTestCase and view the implementation of its openArtifact method. For more information, see Optional Customizations for Opening Task Artifacts.

    This function requires CI/CD Automation for Simulink Check.

    example

    Examples

    collapse all

    You can open a test case artifact by using the function padv.util.openTestCase.

    Open a project. For this example, you can open the Process Advisor example project.

    processAdvisorExampleStart

    Find the test cases in the project by creating and running an instance of the built-in query padv.builtin.query.FindArtifacts. The ArtifactType argument allows you to find test case artifacts. Since test cases are sub-file artifacts of the test file, you need to set FilterSubFileArtifacts to false to see the test cases in the query results. You can view the test case names by using the Alias property of the artifacts. The order of the test cases might be different on your machine.

    q = padv.builtin.query.FindArtifacts(ArtifactType="sl_test_case",FilterSubFileArtifacts=false);
    testCases = q.run;
    testCases.Alias
    ans = 
    
        "HLR_12"
    
    
    ans = 
    
        "HLR_13"
    
    
    ans = 
    
        "HLR_11"
    
    
    ans = 
    
        "HLR_8"
    
    
    ans = 
    
        "HLR_7"
    
    
    ans = 
    
        "HLR_6"

    Open the first test case artifact returned by the query by using the padv.util.openTestCase.

    padv.util.openTestCase(testCases(1));
    The function opens the test case in Test Manager.

    If you want to automatically load the test results for the test case, you can specify the loadTestResults argument as true.

    padv.util.openTestCase(testCases(1),true);
    The test cases in this example project do not have test results available, so only the test case opens in Test Manager.

    You can customize how Process Advisor opens test cases by using the padv.util.openTestCase function inside the openArtifact method of a task. For example, by default, when you run the built-in task padv.builtin.task.RunTestsPerTestCase and open a test case from the I/O column in Process Advisor, the task opens the test case in Test Manager and automatically loads the available test results. But suppose that you do not want the task to load those test results. You can create a custom task that inherits from the built-in task and overrides the openArtifact method of the task to change the behavior for opening artifacts.

    Inside your class definition file, you override the openArtifact method. In this example, the new implementation of the openArtifact method uses the padv.util.openTestCase function to open the test case, but specifies the argument loadTestResults as false to prevent the test results from loading in Test Manager.

    classdef MyRunTestsPerTestCaseTask < padv.builtin.task.RunTestsPerTestCase
        methods
            function obj = MyRunTestsPerTestCaseTask(options)
                arguments
                    options.Name = "MyRunTestsPerTestCaseTask";
                    options.Title = "My Custom Run Tests per Test Case Task";
                end
                obj@padv.builtin.task.RunTestsPerTestCase(Name = options.Name);
                obj.Title = options.Title;
            end
            function status = openArtifact(~,artifact,~)
                % Override openArtifact method
    
                % Validate input arguments
                arguments
                    ~
                    artifact (1,1) padv.Artifact {mustBeNonempty}
                    ~
                end
    
                % Check if the artifact type is 'sl_test_case'
                if strcmp(artifact.Type,"sl_test_case")
                    % Open the test case but do not any load test results
                    status = padv.util.openTestCase(artifact,false);
                else
                    % Unsupported artifact type
                    status = false;
                end
            end
        end
    end

    To see the original implementation of the openArtifact method for the built-in task padv.builtin.task.RunTestsPerTestCase, you can open the class definition file and inspect the openArtifact method.

    open padv.builtin.task.RunTestsPerTestCase
    For more information, see Optional Customizations for Opening Task Artifacts.

    Input Arguments

    collapse all

    Test case artifact, specified as a padv.Artifact object.

    Load test results for the test case into Test Manager, specified as a numeric or logical 0 (false) or 1 (true).

    Output Arguments

    collapse all

    Status of operation, returned as either:

    • 1 (true) — The function was able to open the test case successfully.

    • 0 (false) — The function failed to open the test case.

    Go to top of page