Main Content

Author, Import, Link, and Justify Requirements Programmatically

You can use the Requirements Toolbox™ API to author, import, link, and justify requirements programmatically. The API provides an alternative to interactively performing these actions in the Requirements Editor. For more information about interactively authoring, importing, linking, and justifying requirements, see Use Requirements to Develop and Verify MATLAB Functions.

Items that you can author, view, and edit in the Requirements Editor, such as requirements, links, and justifications, also have equivalent objects that you can access programmatically in the MATLAB® Command Window by using the Requirements Toolbox API.

This example shows how to author requirements, import additional requirements from Microsoft® Word, and then link and justify the requirements programmatically. You can only run this example on Microsoft Windows® platforms.

Author Requirements

Create a requirement set to contain the requirements by using the slreq.new function.

myReqSet = slreq.new("MyRequirementSet");

The function returns the requirement set object as an slreq.ReqSet object. Add a parent requirement to the requirement set by passing the slreq.ReqSet object as an input to the add method.

parentReq1 = add(myReqSet);

The method returns the requirement as an slreq.Requirement object. Add text to the Summary and Description properties. Access these properties by using dot notation.

parentReq1.Summary = "Parent Requirement 1";
parentReq1.Description = "This is the first parent requirement in the requirement set.";

Add a second parent requirement to the requirement set. Specify the Summary and Description properties when you add the requirement.

parentReq2 = add(myReqSet,Summary="Parent Requirement 2", ...
    Description="This is the second parent requirement in the requirement set.");

Add two child requirements to the first parent requirement by passing the slreq.Requirement object as an input to the add method.

childReq1 = add(parentReq1,Summary="Child Requirement 1.1");
childReq2 = add(parentReq1,Summary="Child Requirement 1.2");

Return an array of the parent requirements for the requirement set by passing the slreq.ReqSet object as an input to the children method.

parentReqs = children(myReqSet)
parentReqs=1×2 object
  1×2 Requirement array with properties:

    Type
    Id
    Summary
    Description
    Keywords
    Rationale
    CreatedOn
    CreatedBy
    ModifiedBy
    IndexEnabled
    IndexNumber
    SID
    FileRevision
    ModifiedOn
    Dirty
    Comments
    Index

Return an array of the child requirements for the first parent requirement by passing the slreq.Requirement object as an input to the children method.

childReqs = children(parentReq1)
childReqs=1×2 object
  1×2 Requirement array with properties:

    Type
    Id
    Summary
    Description
    Keywords
    Rationale
    CreatedOn
    CreatedBy
    ModifiedBy
    IndexEnabled
    IndexNumber
    SID
    FileRevision
    ModifiedOn
    Dirty
    Comments
    Index

Save the requirement set.

save(myReqSet)

Import Requirements

The requirement specification MyRequirementSpecification.docx is a Microsoft Word document that contains six requirements arranged in a basic hierarchy.

Import the requirements as references to the external requirements, called referenced requirements, by using the slreq.import function. Importing requirements as referenced requirements allows you to continue to manage the requirements in Microsoft Word.

[count,filePath,myImportedReqSet] = slreq.import("MyRequirementSpecification.docx", ...
    AsReference=true);

The function returns the number of imported referenced requirements, the file path to the requirement set, and the slreq.ReqSet object for the requirement set. Get a handle to the import node of the requirement set by passing the slreq.ReqSet object as an input to the children method.

topRef = children(myImportedReqSet);

The import node is returned as an slreq.Reference object. Return an array of the parent requirements in the requirement set by passing the slreq.Reference object as an input to the children method.

parentRefs = children(topRef)
parentRefs=1×2 object
  1×2 Reference array with properties:

    Id
    CustomId
    Artifact
    ArtifactId
    Domain
    UpdatedOn
    CreatedOn
    CreatedBy
    ModifiedBy
    IsLocked
    Summary
    Description
    Rationale
    Keywords
    Type
    IndexEnabled
    IndexNumber
    SID
    FileRevision
    ModifiedOn
    Dirty
    Comments
    Index

The method returns the referenced requirements under the import node as slreq.Reference objects.

Open the Word document.

winopen("MyRequirementSpecification.docx")

Under Parent Requirement 1, replace the existing text with this text: This is the first parent requirement in the requirement set. Save the Word document, then close it.

Check if the Word document associated with the import node has changed since the document was imported.

tf = hasNewUpdate(topRef)
tf = logical
   1

Update the requirement set.

[status,changeList] = updateReferences(myImportedReqSet,topRef)
status = 
'Update completed. Refer to Comments on Import1.'
changeList = 
    'Updated: Parent Requirement 1. Properties: description
     '

Save the requirement set.

save(myImportedReqSet)

Create Links

Create a link between the two requirements that have the summary Parent Requirement 1 by using the slreq.createLink function.

parentRef1 = parentRefs(1);
myLink = slreq.createLink(parentRef1,parentReq1);

The function returns the link as an slreq.Link object.

When you create links by using the Requirements Editor interface, Requirements Toolbox determines which item is the source and which is the destination. When you create links by using the slreq.createLink function, you have to indicate which item is the source and which is the destination. When you create links between requirements and design or test items, set the requirement as the destination. Requirements Toolbox determines the link type.

Return the link set object for the link by passing the slreq.Link object as an input to the linkSet method.

myLinkSet1 = linkSet(myLink);

The function returns the link set object as an slreq.LinkSet object.

Save the link set.

save(myLinkSet1);

Justify Requirements

If requirements in your requirement set are not meant to be implemented or verified, you can justify their exclusion from the implementation and verification status.

Justify the requirement that has the summary Parent Requirement 1 for implementation.

Add a justification to the MyRequirementSet requirement set by passing the slreq.ReqSet object as an input to the addJustification method. Create a link that has the type Implement between the requirement and the justification by using the justifyImplementation method.

jt1 = addJustification(myReqSet);
implLink = justifyImplementation(parentReq1,jt1);

The addJustification method returns the justification as an slreq.Justification object. When you add justifications programmatically, Requirements Toolbox stores the justification under a parent justification. If a parent justification does not exist, the software creates one. Return the parent justification by passing the slreq.Justification object as an input to the parent method.

parentJust = parent(jt1);

Next, justify the requirement that has the summary Parent Requirement 1 for verification.

Add a justification to the MyRequirementSet requirement set by using the addJustification method. Create a link that has the type Implement between the requirement and the justification by using the justifyVerification method.

jt2 = addJustification(myReqSet);
verifLink = justifyVerification(parentReq1,jt2);

Save the requirement set.

save(myReqSet)

Return the link set for the link, then save it.

myLinkSet2 = linkSet(verifLink);
save(myLinkSet2);

Find Loaded Requirements Toolbox Objects

You can find loaded Requirements Toolbox objects by searching all of the loaded objects or by searching for objects in a requirement set or link set.

Find the loaded requirement sets by using the slreq.find function.

loadedReqSets = slreq.find(Type="ReqSet")
loadedReqSets=1×2 object
  1×2 ReqSet array with properties:

    Description
    Name
    Filename
    Revision
    Dirty
    CustomAttributeNames
    CreatedBy
    CreatedOn
    ModifiedBy
    ModifiedOn

Find the loaded requirements by using the slreq.find function. Then, find the loaded requirements in the MyRequirementSet requirement set by passing the slreq.ReqSet object as an input to the find method. Compare the results.

loadedRequirements1 = slreq.find(Type="Requirement")
loadedRequirements1=1×4 object
  1×4 Requirement array with properties:

    Type
    Id
    Summary
    Description
    Keywords
    Rationale
    CreatedOn
    CreatedBy
    ModifiedBy
    IndexEnabled
    IndexNumber
    SID
    FileRevision
    ModifiedOn
    Dirty
    Comments
    Index

loadedRequirements2 = find(myReqSet,Type="Requirement")
loadedRequirements2=1×4 object
  1×4 Requirement array with properties:

    Type
    Id
    Summary
    Description
    Keywords
    Rationale
    CreatedOn
    CreatedBy
    ModifiedBy
    IndexEnabled
    IndexNumber
    SID
    FileRevision
    ModifiedOn
    Dirty
    Comments
    Index

The results are the same because the MyRequirementSet requirement set is the only loaded requirement set that contains slreq.Requirement objects.

Find the loaded links by using the slreq.find function. Then, find the loaded links in the second link set by passing the slreq.LinkSet object as an input to the find method. Compare the results.

loadedLinks1 = slreq.find(Type="Link")
loadedLinks1=1×3 object
  1×3 Link array with properties:

    Type
    Description
    Keywords
    Rationale
    CreatedOn
    CreatedBy
    ModifiedOn
    ModifiedBy
    Revision
    SID
    Comments

loadedLinks2 = find(myLinkSet2)
loadedLinks2=1×2 object
  1×2 Link array with properties:

    Type
    Description
    Keywords
    Rationale
    CreatedOn
    CreatedBy
    ModifiedOn
    ModifiedBy
    Revision
    SID
    Comments

The results are different because both slreq.LinkSet objects contain slreq.Link objects.

Clear and Load Requirement Sets and Link Sets

You can clear individual requirement sets from memory. Close the MyRequirementSpecification requirement set by passing the slreq.ReqSet object as an input to the close method.

close(myImportedReqSet)

When you close a requirement set, Requirements Toolbox also closes its registered link sets, unless another artifact that contains link sources or destinations for the link set is still loaded. Search for the link sets that are still loaded.

loadedLinkSets = slreq.find(Type="LinkSet")
loadedLinkSets=1×2 object
  1×2 LinkSet array with properties:

    Description
    Filename
    Artifact
    Domain
    Revision
    Dirty
    CustomAttributeNames

You cannot clear individual link sets from memory. Instead, clear all loaded requirement sets and link sets by using the slreq.clear function. Confirm that the link sets were cleared from memory by using the slreq.find function.

slreq.clear
loadedLinkSets = slreq.find(Type="LinkSet")
loadedLinkSets = 

  0×0 LinkSet array with properties:

    Description
    Filename
    Artifact
    Domain
    Revision
    Dirty
    CustomAttributeNames

When you clear the requirements and links from memory, the variables that remain in the workspace are no longer usable. Clear the workspace by using clear.

clear

Load the MyRequirementSet requirement set by using the slreq.load function.

myReqSet = slreq.load("MyRequirementSet");

Loading the requirement set also loads the registered link sets for the requirement set.

loadedLinkSets = slreq.find(Type="LinkSet")
loadedLinkSets=1×2 object
  1×2 LinkSet array with properties:

    Description
    Filename
    Artifact
    Domain
    Revision
    Dirty
    CustomAttributeNames

See Also

Classes

Functions

Related Topics