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 in Projects

To link to a requirement from a MATLAB® test in a project:

  1. Open the project.

  2. Open the Requirements Editor. On the Apps tab, under Verification, Validation, and Test, click Requirements Editor.

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

  4. Select a requirement.

  5. Open the MATLAB Test Manager. In the MATLAB Toolstrip, in the Project tab, in the Tools section, click MATLAB Test Manager.

  6. Expand the test file. Right-click the test and click Requirements > Link to Selection in Requirements Browser.

    A test is selected in the is selected in the MATLAB editor.

When you select a requirement, the Requirements Editor displays the linked tests in the right pane, under Links.

The Requirements Editor displays a link to the requirement with the index 2.2.2. The cursor points to the requirement and the requirement is selected. The requirement is highlighted in blue.

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:

  1. Open the MATLAB Test Manager and the Requirements Editor.

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

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

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

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.

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.

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:

  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, generate a traceability matrix that contains the requirements and tests in the project. Generate the matrix by using the Code Quality Dashboard:

  1. Open the Code Quality Dashboard. For more information, see Open the Code Quality Dashboard App.

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

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

Traceability matrix with requirement sets on the top and test files on the left. The matrix only shows requirements that are missing links.

See Also

Apps

Functions

Classes

Related Examples

More About