Integrating results from a custom authored MUnit script as a test

You can integrate the results from a MATLAB xml Unit test by linking to a test script. In this example, you link a requirement to a MATLAB Unit test case script. The verification status in the Simulink Requirements Editor reflects the test results.

Workflow

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. You want to link the results of the test to a requirement in counter_req.slreqx. Follow these steps to create and view the verification status with a test case called testCounterStartsAtZero in CounterTests.m:

  1. You start with opening the Requirements set counter_req.slreqx'.

  2. You create and register the Linktype using the API.

  3. You create the link.

  4. You view the Verification Status.

Section 1: Open the Requirements Set

Open the requirements file counter_req.slreqx in the Requirements Editor.

reqSet = slreq.open('counter_req.slreqx');

This will open the requirements set 'counter_req.slreqx'.

Section 2: Create and Register Custom Linktype

The domain registration needed for this example is written in 'linktype_mymljunitresults.m'. The template file for domain registrations is available at: matlabroot/toolbox/slrequirements/linktype_examples/linktype_TEMPLATE.m. Take a look at the implementation of GetResultFcn in the domain registration file:

edit linktype_mymljunitresults;

Register the custom linktype:

rmi register linktype_mymljunitresults;

If the command returns any warning, then you must unregister the file and follow the command again. Unregister the file by entering: rmi unregister linktype_mymljunitresults

Section 3: Create the Link

Make the struct containing properties of the external test. Follow these steps to create the link:

externalSource.id = 'testCounterStartsAtZero';
externalSource.artifact = 'counterTests.m';
externalSource.domain = 'linktype_mymljunitresults';

Find the requirement related to the link by typing:

requirement = reqSet.find('Type', 'Requirement', 'SID', 2);

Create the link by entering:

link = slreq.createLink(requirement, externalSource);

This creates the link as test case testCounterStartsAtZero to the requirement 'SID'. In Requirements Editor, the link appears in the Links Confirmed by section.

Section 4: View the Verification Status

To update the verification status for the requirements set, type:

reqSet.updateVerificationStatus;

Fetch the verification status for the requirement:

status = reqSet.getVerificationStatus;

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

The verification status for the requirements for the testCounterStartsAtZero is fully verified. The Requirements Editor shows the overall verfication statuses for all the other requirements links associated with counter_req.slreqx.

reqSet = slreq.open('counter_req.slreqx');

If you are unable to see the verification status, click on the Refresh button to see the verification status for the requirements in the Requirements Editor. The verification status shows that out of three tests, one test passed.

Clear the requirements once the simulation is completed.