Main Content

Justify Missing Coverage using MATLAB Test Manager

Since R2025a

This example shows how to use MATLAB® Test Manager to analyze code coverage, view the code coverage report, and justify missing outcomes, and also explains the differences between coverage reports for the most recent run and run history.

Open the Project

This example uses the MATLABShortestPath project. The project consists of a src folder, which contains the shortest_path function, a tests folder, which contains tests for the function, and a requirements folder, which contains the software requirements implemented using Requirements Toolbox™. The shortest_path function finds the shortest path between two nodes in a graph.

prj = openProject("MATLABShortestPath");

Open MATLAB Test Manager and Run Tests

Open the MATLAB Test Manager.

matlabTestManager;

Click the Configure code coverage collection settings button coverage_16.png, select Enable code coverage, and set the slider to MC/DC.

enable-coverage.png

Click the Run tests button run_16.png.

View Coverage Results

In the Test Manager, the top row gives a summary of the state of the project testing. Fourteen tests pass, one failed, and 88% of code statements executed. To see more details, point your cursor to the Statement button in the Test Manager summary.

statement-icon-hover.png

Open the Code Quality Dashboard.

codeQualityDashboard;

code-quality-dashboard.png

Create the code coverage report by clicking the Statement button in Test Manager.

code-coverage-report.png

The coverage numbers in the code coverage report and the Code Quality Dashboard match.

Justify Coverage Outcome

If you analyze coverage with the MC/DC metric selected, then by default the code coverage report opens showing the MC/DC results. Justifying code coverage outcomes from the MC/DC or condition coverage view is not supported. Instead, click the Currently viewing dropdown and select Decision.

In the Source Details section, create a justification for line 21 by clicking the entry point for the code block if (~isAdjMatrixValid(adjMatrix)). In the Create Coverage Justification dialog box, enter a reason for the justification. For this example, enter Defensive coding and click OK.

justification-reason.png

In the Test Manager, in the summary, the coverage button updates to new values after you apply the coverage filter. Decision coverage increased from 80.6% to 83.3%, and the statement coverage increased from 88% to 90%. In the Code Quality Dashboard, you must refresh the metrics to see the updated values. You do not need to re-run the tests until you want to lock the filtered numbers into your run history.

Archive Justifications into Run History

In Test Manager, click the Run tests button run_16.png. When you run the test again, currently applied coverage filters are logged into the run history. Coverage reports created from the run history are read-only, so you cannot add or remove justifications from those reports.

In the Test Manager, open the All Tests in Current Project list and select your first run, which is the last option under Previous runs. The first run shows the statement coverage results before you created the justification, which was 88%. Then, select the second run under the Previous runs to see the updated value of 90%.

Click the Statement button from this previous run and change the Currently viewing drop down to Decision, and scroll to Source Details. Note that you cannot filter the unsatisifed coverage objectives because you created the report from the Previous runs view.

cannot-create-filters.png

Create Coverage Report from Code Quality Dashboard

In the Code Quality Dashboard, in the yellow banner, click Refresh Metrics. Then, on the Code Coverage card, click the three dot menu three-dot-icon.png and select Open Report. Coverage reports created from the Code Quality Dashboard open with the most recent results, apply any coverage justifications that you have already created, and are writable, so you can add or remove coverage justifications.

code-coverage-report-2.png

See Also

Functions

Classes

Apps

Topics