Main Content

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:

  1. Open a requirement set in the Requirements Editor (Requirements Toolbox). For more information, see Create, Open, and Delete Requirement Sets (Requirements Toolbox).

  2. Open a MATLAB test file.

  3. Select the function declaration line for the test.

    A function declaration line for a test is selected in the MATLAB editor.

  4. In the Requirements Editor, select a requirement.

  5. In the toolstrip, click Add Link > Link from Selection in MATLAB Editor.

    The Link from Selection in MATLAB Editor menu item is selected for a requirement.

  6. 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:

  1. Open the MATLAB Test Manager. For more information, see Open the MATLAB Test Manager App.

  2. Open the Requirements Editor. For more information, see Open the Requirements Editor App (Requirements Toolbox).

  3. 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.

  4. 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).

  5. In the Run Tests dialog, select the tests to run, then click Run Tests.

    The Run Tests dialog shows the linked tests for the requirement set, the test files, the test result for each test, and the index of the requirements that the tests verify.

    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.

The Link from Selection in MATLAB Editor menu item is selected for a requirement.

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.

The mouse points to the Verified column for a requirement set that has four requirements. The tooltip indicates that four requirements link to tests that passed, one links to a test that failed, and three do not have links to tests.

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.

Requirements section of the dashboard with passed, failed, and unlinked requirements.

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.

The mouse points to the legend in the requirements section of the dashboard. The tooltip indicates the number of requirements that link to tests that passed, failed, were not run, and are not linked. The tooltip also indicates the total number of requirements in the project.

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:

  1. Open the Requirements Editor.

  2. Enable the verification status by selecting Columns > Verification Status.

  3. Identify requirements that have an empty bar in the Verified column.

    The mouse points to status bar the Verified column in the Requirements Editor for an unlinked requirement, which has a colorless bar. The tooltip indicates that the requirement does not have links.

To identify missing links between requirements and MATLAB tests, use a traceability matrix:

  1. Open the Traceability Matrix window. In the Requirements Editor, click Traceability Matrix.

  2. In the Traceability Matrix window, click Add to create a matrix.

  3. 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).

  4. Click Generate Matrix to create the matrix.

  5. 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.

Traceability matrix with a requirement set on the left and a test file on top that only shows requirements that are missing links.

See Also

Apps

Functions

Classes

Related Examples

More About