Main Content

slreq.verification.services.JUnit Class

Namespace: slreq.verification.services
Superclasses:

Work with external results sources

Since R2020a

Description

Instances of the slreq.verification.services.JUnit provides utilities for interpreting JUnit result files for verification.

Creation

JUnitService = slreq.verification.services.JUnit() directs the result fetching logic to the XML file.

Output Arguments

expand all

Services used in GetResultFcn to script up result fetching logic

Methods

The methods can be run on an instance of the JUnit class such as JUnitService illustrated above.

For the resultFile that contains result for a test with ID in testID, the getResult function returns the result for that testID. The output result is a struct with fields status and timestamp for that testID:

result = JUnitService.getResult(testID, resultFile);

The getAllResults similarly fetches the result for all tests in the resultFile using:

allResults = JUnitService.getAllResults(resultFile);

where allResults is an array of structs with fields testid, status, and timestamp for all the tests in the resultFile. If there are errors or diagnostic output available in the JUnit output for that test, the error or info fields contain that text string.

Examples

collapse all

In this example, you integrate the results from a MATLAB® xml Unit test by linking to a test script. The verification status in the Requirements Editor reflects the test results. This example uses a requirement set file named counter_req and an XML unit test file named myMUnitResults.xml. This file contains a test case named testCounterStartsAtZero.

Register the Custom Document Interface

Before creating the links, you need to register the custom document interface from the requirements set file. Open the requirements file counter_req.slreqx in the Requirements Editor.

myReqSet = slreq.open("counter_req.slreqx");

requirements_set_munit.png

Register the custom document interface that integrates the results from the MUnit test file.

rmi register custom_mymljunitresults

The custom logic in the GetResultFcn function locates the result file that corresponds to the test case and fetches the results from that XML file. The test is run with a customized test runner using XML Plugin producing a JUnit output. The XML Plugin class creates a plugin that writes test results to a file called myMUnitResults.xml.

If the register command returns a warning, then you must unregister the file and run the command again. To unregister the file, enter rmi unregister custom_mymljunitresults.

Create the Link

Make the struct containing properties of the external test. To create the link, at the command prompt, enter:

externalSource.id = "testCounterStartsAtZero";
externalSource.artifact = "counterTests.m";
externalSource.domain = "custom_mymljunitresults";

The requirement related to the link has its SID set to 2. To find the requirement related to the link, enter:

requirement = find(myReqSet,Type="Requirement",SID=2);

To create the link, enter:

link = slreq.createLink(requirement,externalSource);

This command creates the link between the test case testCounterStartsAtZero and the requirement with the SID of 2.

In order to avoid stale results, make sure that the timestamp of result file is latest than the timestamp of link creation. Open myMUnitResults.xml, make a dummy change in the file and save it again to get the latest timestamp.

In Requirements Editor, the link appears in the right pane, under Links.

View the Verification Status

To view the verification status, you need to first update the verification status for the requirement set. At the MATLAB command prompt, type:

updateVerificationStatus(myReqSet)

To see the verification status column in the Requirements Editor, ensure that showColumns_16.png Columns > Verification Status is selected. After the update, fetch the verification status for the requirement:

status = getVerificationStatus(myReqSet)
status = struct with fields:
        failed: 0
     justified: 0
          none: 2
        passed: 1
         total: 3
    unexecuted: 0

The Requirements Editor shows the verification status for entire requirements set that are passed or failed.

verification_status_passed_test_counter.png

The verification status for the requirements for the testCounterStartsAtZero is fully verified. Open the Requirements Editor to see the verification status:

myReqSet = slreq.open("counter_req.slreqx");

The Requirements Editor shows the verification status for each requirement in the requirement set. The verification status for requirements for the counterSetsValue is fully verified.

overall_verification_status_pass_test_counter.png

The verification status shows that out of three tests, one test passed. Click Refresh to see the verification status for the requirements in the Requirements Editor.

Unregister the custom document interface.

rmi unregister custom_mymljunitresults

Version History

Introduced in R2020a