Work with external results sources
Instances of the
utilities for interpreting JUnit result files for verification.
directs the result fetching logic to the XML file.
JUnitService — Services used for XML files
Services used in
GetResultFcn to script up result
The methods can be run on an instance of the
JUnit class such as
JUnitService illustrated above.
resultFile that contains result for a test with ID in
getResult function returns the
result for that
testID. The output
result is a
struct with fields
timestamp for that
result = JUnitService.getResult(testID, resultFile);
getAllResults similarly fetches the
for all tests in the
allResults = JUnitService.getAllResults(resultFile);
allResults is an array of structs with fields
timestamp for all the tests in the
If there are any errors or diagnostic output available in the JUnit output for that
info fields contain that text
Integrating Results from a Custom Authored MUnit Script as a Test
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. To run this example, click Open Example and run it. This example uses:
A requirements set file named counter_req.slreqx.
A xml Unit test file named
myMUnitResults.xml.This file contains a test case named
Step 1: Register the Link Type
Before creating the links, you need to register the link type from the requirements set file. Open the requirements file
counter_req.slreqx in the Requirements Editor.
reqSet = slreq.open('counter_req.slreqx');
Register the link type that is specific to the MUnit test file. The domain registration needed for this example is
linktype_mymljunitresults.m. To register the custom linktype
rmi register linktype_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. For more information about
GetResultFcn, see Links and Link Types. 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
Note: If the register command returns any warning, then you must unregister the file and run the command again. To unregister the file, enter
rmi unregister myMUnitResults.xml
Section 2: Create the Link
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 = 'linktype_mymljunitresults';
The requirement related to the link has its SID set to 2. To find the requirement related to the link, enter:
requirement = reqSet.find('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.
Note: 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.
Section 3: 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:
To see the verification status column in the Requirements Editor, ensure that Columns > Verification Status is selected. After the update, fetch the verification status for the requirement:
status = reqSet.getVerificationStatus
status = struct with fields:
The Requirements Editor shows the verification status for entire requirements set that are passed or failed.
The verification status for the requirements for the
testCounterStartsAtZero is fully verified. Open the Requirements Editor to see the verification status:
reqSet = 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.
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 link type.
rmi unregister linktype_mymljunitresults;
Introduced in R2020a