Main Content

Measure and Monitor Project Quality

Measure and monitor the quality of MATLAB® code and tests in Projects by using the Code Quality Dashboard. The dashboard collects and displays the quality metric MATLAB code, test files, and requirement sets in the open project and its referenced projects. The dashboard displays metrics for code analysis, test results, code coverage results, and requirements verification.

Monitor Quality Metrics

Open a project. Then, in the Project tab, in the Tools section, under Apps, click Code Quality Dashboard.

Note

By default, the dashboard prompts you to enable artifact tracing the first time you open a project. Click Enable and Continue to allow the dashboard to track tool outputs and detect outdated metric results.

Code Quality Dashboard with metric results for a project.

The dashboard has four sections:

  • Code Analyzer displays coding problems.

  • Tests displays test results.

  • Code Coverage displays code coverage results from tests.

  • Requirements displays requirements verification status.

Each section of the dashboard displays a timestamp that indicates when the software collected the results.

Tip

You can programmatically retrieve the metrics by using the matlabtest.codequalitydashboard.getMetrics function.

Check for Coding Problems

The Code Analyzer section displays information about coding errors, warnings, and improvement opportunities for the MATLAB code and test files in your project.

Code Analyzer section of the dashboard with 1 error and 2 info.

The Code Quality Dashboard uses the MATLAB Code Analyzer to check MATLAB code and test files in the project for coding problems. For more information on the MATLAB Code Analyzer, see Check Code for Errors and Warnings Using the Code Analyzer.

To collect and display code analyzer metric results, update the dashboard. For more information, see Update the Dashboard.

To view details about the coding problems, open the code analyzer report by clicking the Code Analyzer section. For more information, see MATLAB Code Analyzer Report.

Verify Code by Running Tests

The Tests section displays the current test results from the MATLAB Test Manager.

Tests section of the dashboard with some passed and some failed tests.

The MATLAB Test Manager manages MATLAB tests and test results for your project. For more information, see Manage Tests and Results by Using the MATLAB Test Manager.

To collect test metric results, run tests by using the MATLAB Test Manager. Running test suites or tests in the project updates the test metric results with aggregated results from multiple runs.

To view detailed test results, open the MATLAB Test Manager by clicking the Tests section.

Collect Code Coverage

The Code Coverage section displays coverage results from the MATLAB Test Manager.

Code coverage section of the dashboard with results for all metric levels.

Code coverage indicates how thoroughly your tests execute functions, statements, or conditional logic in your code files. For more information, see Collect Code Coverage Metrics for MATLAB Source Code.

To collect and display code coverage metric results, enable coverage in the MATLAB Test Manager, then run all tests in the project. Running test suites or selected tests does not update the coverage metric results for the project.

To view detailed code coverage results, open the code coverage report by clicking the Code Coverage section.

Verify Requirements

If you have Requirements Toolbox™, the Requirements section displays the requirements verification status for the requirements in the project.

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

In Requirements Toolbox, the requirements verification status reflects the results of verification items linked to requirements, including Simulink® tests. In the Code Quality Dashboard, the requirements verification status reflects only the test results for linked MATLAB tests from the MATLAB Test Manager. For more information, see Verify Requirements in Projects with MATLAB Tests.

To collect requirements metric results, run tests by using the MATLAB Test Manager or the Code Quality Dashboard. Running test suites or tests updates the requirements metric results with aggregated results from multiple runs.

To view requirements, open the Requirements Editor by clicking the Requirements section.

Note

Collecting requirements metric results and opening the Requirements Editor requires Requirements Toolbox.

Update the Dashboard

Monitor the quality of your project as you make changes and collect new results by updating the metrics. You can update all metrics in the dashboard, update individual sections, or collect new metrics by running tests.

Update All Metrics

When you make changes to artifacts in the project or collect new results, a banner indicates that the project artifacts have changed.

Code Quality Dashboard banner that indicates that project files have changed.

To retrieve the current status of the project artifacts, click Update Artifacts. When there are more recent results for project artifacts than what is displayed in the dashboard, icons indicate that the metrics are stale.

Code Analyzer section of the dashboard with indication of stale metrics.

Additionally, the dashboard displays a banner that indicates that there are stale results.

Code Quality Dashboard banner that indicates that metric results are stale.

To refresh all of the results in the dashboard, click Refresh All.

Update Individual Metrics

To update metric results for an individual section, in that section, click the three-dot icon and select Refresh Data.

Alternatively, to simultaneously run tests and update metric results for the Tests, Coverage, and Requirements sections, click the three-dot icon in one of those sections and select Run Tests and Refresh Data.

Collect New Metrics by Running Tests

You can collect new metrics by clicking the Run button .

Clicking the Run button :

  • Runs all tests in the open project and its referenced projects

  • Collects coverage for the tests

  • Verifies requirements that link to the tests

Note

Clicking the Run button in the Code Quality Dashboard collects coverage using the metric level specified in the MATLAB Test Manager. The dashboard enables and collects coverage even if coverage is disabled in the MATLAB Test Manager.

To stop the tests from running to completion, click the Stop button .

Alternatively, you can collect new metrics by using the matlabtest.codequalitydashboard.runTestsAndRefreshData function.

Export Code Quality Metrics

You can export current results in the Code Quality Dashboard to a JSON file by using the matlabtest.codequalitydashboard.exportMetrics function.

See Also

Apps

Functions

Related Topics