Linking to a Test Script
In this workflow, you link a requirement to a MATLAB®script using theOutgoing Links Editorand the API. The verification status in theRequirements Editorreflects the test results. These illustrations follow the workflow for including external test results in the requirement verification status. For more information, seeInclude Results from External Sources in Verification Status.
Linking to a Test Script Using the Outgoing Links Editor
Create a requirement set calledcounter_req.slreqx
in theRequirements Editorand save it in a writable location. This requirement set has child requirements that have requirement IDs and descriptions. For more details on how to create requirement sets, seeWork with Requirements in the Requirements Editor.
You have a MATLAB script calledrunmytests.m
that runs a test for theCounter
class inCounter.m
. The test script contains custom methods that write results a TAP format to a file namedresults.tap
. Assume that you have run the test and it has produced theresults.tap
file that contains the results of the test. You want to link the results of the test to a requirement incounter_req.slreqx
. Follow these steps to create and view the verification status with a test case calledcounterStartsAtZero
inrunmytests.m
script:
Create the Register the Link Type
Open the template file atmatlabroot/toolbox/slrequirements/linktype_examples/linktype_TEMPLATE.m
. Follow these steps:
Create a new MATLAB file.
Copy the contents of
linktype_TEMPLATE
into the new file. Save the file aslinktype_mymscripttap.m
.In
linktype_mymscripttap.m
Replace the function name
linktype_TEMPLATE
withlinktype_mymscripttap.m
.Set
linkType。标签
as'MScript TAP Results'
.Set
linkType。Extensions
as{'.M'}
.Uncomment the command for
GetResultFcn
in order to use it inlinktype_mymscripttap
and enter:linktype.GetResultFcn = @GetResultFcn; ......... function result = GetResultFcn(link) testID = link.destination.id; testFile = link.destination.artifact; resultFile = getResultFile(testFile); if ~isempty(resultFile) && isfile(resultFile) tapService = slreq.verification.services.TAP(); result = tapService.getResult(testID, resultFile); else result.status = slreq.verification.Status.Unknown; end end function resultfile = getResultFile(testFile) resultMap = ["runmytests.m", "results.tap";... "othertests.m", "results2.tap"]; resultfile = resultMap(resultMap(:,1) == testFile,2); end
GetResultFcn
uses the utilityslreq.verification.services.TAP
to interpret the result files for verification. Seeslreq.verification.services.TAP
for more details. For more information aboutGetResultFcn
, seeLinks and Link Types.
Save
linktype_mymscripttap.m
.Register the link type. At the command line, enter:
rmi register linktype_mymscripttap
Note
If the command returns a warning, then you must unregister the file and follow step 5 again. Unregister the file by entering:
rmi unregister linktype_mymscripttap
Create the Link
Follow these steps to add the link manually in the Outgoing Links Editor:
Open theRequirements Editorand, in the
counter_req.slreqx
requirement set, right-click the child requirement1.1
and selectOpen Outgoing Links dialog.In the Outgoing Links Editor dialog box, in theRequirementstab, clickNew.
Enter these details to establish the link:
Description:
runmytestscounterStartsAtZero
Document Type:
MScript TAP Results
Document:
runmytests.m
Location:
counterStartsAtZero
ClickOK. The link is highlighted in theLinkssection of theRequirements Editor.
View the Verification Status
Update the verification status in theRequirements Editor. Click刷新to see the verification status for the requirements in theRequirements Editor. This shows the verification status for entire requirement set that passed or failed.
The requirements forcounterStartsAtZero
are fully verified. Here, the verification status shows that out of three tests, one test passed.
Linking to a Test Script Using the API
Create a requirement set calledcounter_req.slreqx
in theRequirements Editorand save it in a writable location. This requirement set has child requirements that have requirement IDs and descriptions. For more details on how to create requirement sets, seeWork with Requirements in the Requirements Editor.
You have a MATLAB script calledrunmytests.m
that runs a test forCounter
class inCounter.m
. The test script contains custom methods that write results in a TAP format to a file namedresults.tap
. Assume that you have run the test and it has produced theresults.tap
file that contains the results of the test. You want to link the results of the test to a requirement incounter_req.slreqx
. Follow these steps to create and view the verification status with a test case calledcounterStartsAtZero
inrunmytests.m
script:
Create and Register the Link Type
Open the template file atmatlabroot/toolbox/slrequirements/linktype_examples/linktype_TEMPLATE.m
. Follow these steps:
Create a new MATLAB file.
Copy the contents of
linktype_TEMPLATE
into the new file. Save the file aslinktype_mymscripttap.m
.In
linktype_mymscripttap.m
:Replace the function name
linktype_TEMPLATE
withlinktype_mymscripttap.m
.Set
linkType。标签
as'MScript TAP Results'
.Set
linkType。Extensions
as{'.M'}
.Uncomment the command for
GetResultFcn
in order to use it inlinktype_mymscripttap
and enter:linktype.GetResultFcn = @GetResultFcn; ......... function result = GetResultFcn(link) testID = link.destination.id; testFile = link.destination.artifact; resultFile = getResultFile(testFile); if ~isempty(resultFile) && isfile(resultFile) tapService = slreq.verification.services.TAP(); result = tapService.getResult(testID, resultFile); else result.status = slreq.verification.Status.Unknown; end end function resultfile = getResultFile(testFile) resultMap = ["runmytests.m", "results.tap";... "othertests.m", "results2.tap"]; resultfile = resultMap(resultMap(:,1) == testFile,2); end
GetResultFcn
uses the utilityslreq.verification.services.TAP
to interpret the result files for verification. Seeslreq.verification.services.TAP
for more details. For more information aboutGetResultFcn
, seeLinks and Link Types.
Save
linktype_mymscripttap.m
.Register the link type. At the command line, enter:
rmi register linktype_mymscripttap
Note
If the command returns a warning, then you must unregister the file and follow step 5 again. Unregister the file by entering:
rmi unregister linktype_mymscripttap
Create the Link
Follow these steps to create the link:
From the MATLAB command prompt, enter:
externalSource.id = 'counterStartsAtZero'; externalSource.artifact = 'runmytests.m'; externalSource.domain = 'linktype_mymscripttap';
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);
counterStartsAtZero
for the requirementSID
. InRequirements Editor, the link appears in theLinks>Confirmed Bysection.
View the Verification Status
Update the verification status. At the MATLAB command prompt, type:
reqSet.updateVerificationStatus
status = reqSet.getVerificationStatus
The requirements forcounterStartsAtZero
are fully verified. Here, the verification status shows that out of three tests, one test passed.
Integrating Results from a MATLAB Unit Test Case
You can also integrate the results from a MATLAB Unit Test case by linking to a test script. The test is run with a customized test runner using a XML plugin that produces a JUnit output. TheXMLPlugin
class creates a plugin that writes test results to an XML file. For more information, seematlab.unittest.plugins.XMLPlugin.producingJUnitFormat
.
你可以注册域名,我创建的链接n the same way as with the test script. The verification status for a set of requirements is shown in theRequirements Editor.