How to Measure Code Coverage in MATLAB - MATLAB
Video Player is loading.
Current Time 0:00
Duration 4:02
Loaded: 4.09%
Stream Type LIVE
Remaining Time 4:02
 
1x
  • Chapters
  • descriptions off, selected
  • en (Main), selected
    Video length is 4:02

    How to Measure Code Coverage in MATLAB

    Some regulated industries may require coverage metrics, and you will need to assess testing effectiveness and completeness for MATLAB® applications and algorithm coverage. MATLAB Test™ includes decision, condition, and MC/DC coverage, as well as MATLAB statement and function coverage.

    Published: 15 Feb 2023

    Hello. This video shows a short demo of how code coverage report in MATLAB can be used to build and analyze code coverage results for your MATLAB code. MATLAB Test extends function and statement coverage to support decision, condition, and MC/DC metrics. These advanced metrics are often required to be shown as part of software quality standards in regulated industries, such as the automotive ISO 26262 standard.

    Now, let's take a look at code coverage using MATLAB Test. You can view a summary of coverage results in the Code Quality Dashboard, which includes coverage metrics you select using the Coverage option in the Test Manager. To view the detailed results in the form of a code coverage report, click on the table in the Coverage section in the Code Quality Dashboard. The report opens up in a browser tab and includes the overall coverage summary, a breakdown of coverage results by individual source files, and a source detail section.

    In the Overall Coverage Summary section, on the right, we have a table that shows the aggregated summary of code coverage research for all the source files in the project. On the left, we see the total number of source files in the project. The breakdown by source section shows coverage results for each source file in the project. By default, it shows percent coverage results for each coverage metric.

    Clicking on the Detailed View button, we see the detailed coverage results for all coverage metrics. You're able to sort the results in this table based on coverage numbers for any metric. Let's start the results by increasing order of statement coverage.

    We see that the file name linearEquationSolver has 100% function coverage, 80% statement coverage, 75% of condition and decision coverage, and 50% of MC/DC. Furthermore, we can select a file in this table to dive into the details of what is covered and what is not in the file in the source detail section. Here, we see that the decision statement on line number 10 has two conditions.

    In a column titled MC/DC, we see the test pairs associated with each condition that show how its outcome independently changes the outcome of the decision statement. In this example, the tests pair for the second condition, which would evaluate to an outcome of True for the decision statement, is not covered, and is hence highlighted in red to indicate the condition outcomes missed by the test. To view details for the other coverage metrics, we can select from the options in the Currently Viewing dropdown. This updates the coverage results displayed in the breakdown by source section and the source detail section.

    Selecting decision coverage, we see that the decision statement on line 5 is partially covered since it is evaluated to False twice, but never evaluated to True from the tests run. Likewise, the decision statement on line 10 is covered for decision coverage, with both the outcomes achieved during testing. Since three of the four possible outcomes were covered for decision coverage, decision coverage for the source file is reported at 75%.

    Similarly, selecting Statement Coverage shows coverage for each statement in the source code. The statements highlighted in red are not hit by the tests run, whereas the ones highlighted in green are hit at least once, as shown in the Column Title statement. That was a quick demo of the Code Coverage Report. Thank you for watching.

    View more related videos