Verify Requirements in Projects with MATLAB Tests
If you have Requirements Toolbox™, you can verify requirements in your project by linking them to tests in the project and running the tests using the MATLAB Test Manager. You can then view the requirements verification status in the Requirements Editor (Requirements Toolbox). Similarly, you can update the test results in the MATLAB Test Manager when you run tests by using the Requirements Editor.
Link Requirements and Tests
To link to a requirement from a MATLAB® test:
Open a requirement set in the Requirements Editor (Requirements Toolbox). For more information, see Create, Open, and Delete Requirement Sets (Requirements Toolbox).
Open a MATLAB test file.
Select the function declaration line for the test.
In the Requirements Editor, select a requirement.
Click Add Link > Link from Selection in MATLAB Editor.
Save the links by clicking Show Links, selecting the link set, and clicking Save.
Note
When you create a link between a requirement and a MATLAB test, Requirements Toolbox sets the link type to Verify
, which enables the
software to verify the requirement.
When you select a requirement, the Requirements Editor displays the linked tests in the right pane, under Links. For more information about requirement links, see Create and Store Links (Requirements Toolbox).
Verify Requirements by Running MATLAB Tests
To verify a requirement by running MATLAB tests, ensure that the requirement and test are in the same project and that the MATLAB Test Manager contains the test.
You can verify specific requirements which runs all linked tests, or you can run specific tests, which verifies only the linked requirements.
Verify Specific Requirements
To verify specific requirements:
Open the MATLAB Test Manager. For more information, see Open the MATLAB Test Manager App.
Open the Requirements Editor. For more information, see Open the Requirements Editor App (Requirements Toolbox).
In the Requirements Editor, right-click a requirement set or an individual requirement and select Run Tests.
Note
Requirements Toolbox finds the tests that link to requirements in the requirement set or to the individual requirement and its child requirements, which can include MATLAB tests and Simulink® tests. For more information, see Review Requirements Verification Status (Requirements Toolbox).
In the Run Tests dialog, select the tests to run, then click Run Tests.
You can also run the tests by passing an slreq.ReqSet
(Requirements Toolbox)
object as an input to the runTests
(Requirements Toolbox)
function.
When you use the Requirements Editor or the runTests
(Requirements Toolbox) function to run the tests that are open in the MATLAB
Test Manager, the MATLAB Test Manager updates the test
results.
Run Specific Tests
To run specific tests, which verifies all requirements linked to those tests, use one of these approaches in the MATLAB Test Manager:
Run all of the tests in the project by clicking the Run button
.
Run the tests in a test suite by clicking All Tests in Current Project, selecting the test suite, then clicking the Run button
.
Run individual tests by pressing Shift or Ctrl and selecting the tests, then right-click and select Run selected.
For more information, see Manage Tests and Results by Using the MATLAB Test Manager.
Tip
You can also run all of the tests in the
project by clicking the Run button in the Code
Quality Dashboard.
When you use the MATLAB Test Manager or Code Quality Dashboard to run tests that link to requirements, Requirements Toolbox updates the verification status for the linked requirements in the Requirements Editor.
Note
You cannot verify requirements by running tests by using the Test Browser.
View and Report Requirements Verification Status
Use the requirements verification status to measure the verification of requirements in your project. You can view the verification status for specific requirements or for the entire project. You can also generate reports that list the verification status for your requirement sets.
View Status for Specific Requirements
To view the verification status for specific requirements, in the Requirements Editor, select Columns > Verification Status, then point to the bar in the Verified column. The tooltip displays details of the verification status. You can view the details for a requirement set, a parent requirement and its children, or a child requirement.
You can also get the verification status for a requirement set programmatically
by passing an slreq.ReqSet
(Requirements Toolbox)
object to the getVerificationStatus
(Requirements Toolbox) function.
View Status for Projects
The Requirements section of the Code Quality Dashboard displays the requirements verification status for all of the requirements in the project, including requirements in referenced projects.
The verification status in the Code Quality Dashboard reflects only the test results from the MATLAB Test Manager. The dashboard does not reflect test results from other sources, including the result of Simulink tests such as Simulink Test™ test cases or Simulink Design Verifier™ proof objective blocks.
To view the fraction of requirements that have a particular result, point to the bar in the graph. To view the details of the requirements verification status, point to the percentages in the legend.
For more information about the Requirements section, see Verify Requirements in Measure and Monitor Project Quality.
Generate Report with Verification Status
To generate a report that includes the requirements verification status for requirement sets, in the Requirements Editor, click Export > Generate Report. In the Report Generation Options dialog box, under Report content, select Verification Status. For more information, see Report Requirements Information (Requirements Toolbox).
You can generate the report programmatically by using the slreq.generateReport
(Requirements Toolbox) function.
Identify Missing Traceability
The requirements verification status in the Code Quality Dashboard indicates if requirements are not linked to MATLAB tests in the project.
To identify requirements in requirement sets that do not have links, use the requirements verification status bar in the Requirements Editor:
Open the Requirements Editor.
Enable the verification status by selecting Columns > Verification Status.
Identify requirements that have an empty bar in the Verified column.
To identify missing links between requirements and MATLAB tests, use a traceability matrix:
Open the Traceability Matrix window. In the Requirements Editor, click Traceability Matrix.
In the Traceability Matrix window, click Add to create a matrix.
In the Select Artifacts dialog, select the requirement set and test file from the Left and Top artifacts list. Alternatively, you can create a traceability matrix with multiple requirement sets or multiple test files. For more information, see Track Requirement Links with a Traceability Matrix (Requirements Toolbox).
Click Generate Matrix to create the matrix.
Show only the requirements that don't have links. In the Filter Panel, click Left > Link > Missing Links or Top > Link > Missing Links, depending on if your requirement set is on the left or on the top.
You can also highlight the requirements that are not linked to tests by clicking Highlight Missing Links.
See Also
Apps
- MATLAB Test Manager | Code Quality Dashboard | Requirements Editor (Requirements Toolbox)
Functions
runTests
(Requirements Toolbox)
Classes
slreq.ReqSet
(Requirements Toolbox)
Related Examples
- Verify Requirements and Address Missing Traceability
- Verify a MATLAB Algorithm by Using Requirements-Based Tests (Requirements Toolbox)
More About
- Verify Requirements with MATLAB Tests (Requirements Toolbox)
- Review Requirements Verification Status (Requirements Toolbox)
- Manage Tests and Results by Using the MATLAB Test Manager
- Measure and Monitor Project Quality
- Track Requirement Links with a Traceability Matrix (Requirements Toolbox)