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 in Projects
To link to a requirement from a MATLAB® test in a project:
Open the project.
Open the Requirements Editor. On the Apps tab, under Verification, Validation, and Test, click Requirements Editor.
Open a requirement set. For more information, see Create, Open, and Delete Requirement Sets (Requirements Toolbox).
Alternatively, you can open all requirement sets in the project by using the Code Quality Dashboard dashboard. For more information, see Open Requirement Sets in the Current Project.
Select a requirement.
Open the MATLAB Test Manager. In the MATLAB Toolstrip, in the Project tab, in the Tools section, click MATLAB Test Manager.
Expand the test file. Right-click the test and click Requirements > Link to Selection in Requirements Browser.
When you select a requirement, the Requirements Editor displays the linked tests in the right pane, under Links.
By default, Requirements Toolbox sets the Type property to Verify
,
which enables the software to verify the requirement.
To save the links, in the Requirements Editor, click Show Links, select the link set, and click Save.
You can also link the requirement to the test by linking directly to the function declaration statement in the MATLAB code. For more information on linking requirements to MATLAB code, see Link Requirements to MATLAB Code (Requirements Toolbox) and 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 and the Requirements Editor.
In the Requirements Editor, enable the verification status. In the Views section of the toolstrip, click the Columns button and ensure that Verification Status is selected.
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.
Tests with unresolved links are disabled. For more information on resolving links, see Load and Resolve Links (Requirements Toolbox).
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 test results also update in the MATLAB Test
Manager.
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.
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 using the Test Browser to run tests.
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.
You can also use the Requirements Editor to view the verification status for the requirements in the project. To open the requirements in the project, click the Requirements section of the Code Quality Dashboard. If you have loaded requirement sets that are not in the current project, a dialog box prompts you to save and close them.
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, generate a traceability matrix that contains the requirements and tests in the project. Generate the matrix by using the Code Quality Dashboard:
Open the Code Quality Dashboard. For more information, see Open the Code Quality Dashboard App.
In the Requirements section of the dashboard, click the three-dot icon and select Generate Traceability Matrix. If you have loaded requirement sets that are not in the current project, a dialog box prompts you to save and close them.
The Traceability Matrix window opens and displays the loaded requirement sets on the top and the tests on the left.
Show only the requirements that do not have links. In the Filter Panel, click Top > Link > Missing Links.
You can also highlight the requirements and tests that are not linked to artifacts in the matrix 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)