{"id":3134,"date":"2023-09-18T03:34:59","date_gmt":"2023-09-18T07:34:59","guid":{"rendered":"https:\/\/blogs.mathworks.com\/developer\/?p=3134"},"modified":"2023-09-18T03:35:40","modified_gmt":"2023-09-18T07:35:40","slug":"measuring-and-monitoring-code-quality","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/developer\/2023\/09\/18\/measuring-and-monitoring-code-quality\/","title":{"rendered":"Measuring and Monitoring Code Quality"},"content":{"rendered":"<div class = rtcContent><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>This is the third instalment in my series on <\/span><a href = \"https:\/\/uk.mathworks.com\/products\/matlab-test.html\"><span style=' text-decoration: underline;'>MATLAB Test<\/span><\/a><span>. My previous posts <\/span><a href = \"https:\/\/blogs.mathworks.com\/developer\/2023\/08\/16\/introducing-matlab-test\/\"><span style=' text-decoration: underline;'>introduced MATLAB Test and the Test Manager<\/span><\/a><span> and the <\/span><a href = \"https:\/\/blogs.mathworks.com\/developer\/2023\/08\/30\/weve-got-you-covered\/\"><span style=' text-decoration: underline;'>use of advanced coverage metrics<\/span><\/a><span>. <\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Today I\u2019m going to look at the Code Quality Dashboard which centralises a variety of metrics for your project and allows you to answer questions such as:<\/span><\/div><ul  style = 'margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif; font-size: 14px; '><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span>Does my code have any issues identified by the <\/span><a href = \"https:\/\/uk.mathworks.com\/help\/matlab\/matlab_prog\/check-code-for-errors-and-warnings.html\"><span style=' text-decoration: underline;'>MATLAB Code Analyzer<\/span><\/a><span>?<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span>Does my project meet required coverage thresholds?<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span>Do I have failing tests and if so, how many?<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span>Are all my requirements linked to tests and have those tests been run?<\/span><\/li><\/ul><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>To explore this more, I\u2019m going to use the example project that comes with MATLAB Test which you can access by running:<\/span><\/div><div style=\"background-color: #F5F5F5; margin: 10px 0 10px 0;\"><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 4px; padding: 6px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >openExample(<\/span><span style=\"color: #a709f5;\">'matlabtest\/CompleteTheVerificationOfAMATLABAlgorithmExample'<\/span><span >)<\/span><\/span><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>As always, the <\/span><a href = \"https:\/\/uk.mathworks.com\/help\/matlab-test\/ug\/measure-and-monitor-project-quality.html\"><span style=' text-decoration: underline;'>documentation provides additional detail<\/span><\/a><span> to what I cover here.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>With your project open, open the Code Quality Dashboard by clicking the icon in the tools gallery:<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: center; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/developer\/files\/codeQualityDashboardPost_1.png\" width = \"392\" height = \"341\" alt = \"codeQuality_toolstrip.png\" style = \"vertical-align: baseline; width: 392px; height: 341px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: center; '><span style=' font-style: italic;'>Open the Code Quality Dashboard from the tools gallery.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>The first time the dashboard opens it will look like this:<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: center; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/developer\/files\/codeQualityDashboardPost_2.png\" width = \"378\" height = \"596\" alt = \"codeQuality_initialState.png\" style = \"vertical-align: baseline; width: 378px; height: 596px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: center; '><span style=' font-style: italic;'>Initial state of Code Quality Dashboard.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>There are 4 sections in the dashboard that bring together metrics from the MATLAB Code Analyzer, code coverage, tests, and requirements. <\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>We\u2019re currently missing test data as we haven\u2019t run them yet \u2013 the tests are not run automatically as this could take a significant amount of time in a large project. You can run the tests from the Test Manager or you can use the button in the dashboard \u2013 click the 3 dots menu to the right of \u201cCoverage\u201d or \u201cTests\u201d and select \u201cRun Tests and Refresh Data\u201d.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: center; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/developer\/files\/codeQualityDashboardPost_3.png\" width = \"554\" height = \"121\" alt = \"codeQuality_runTests.png\" style = \"vertical-align: baseline; width: 554px; height: 121px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: center; '><span style=' font-style: italic;'>Run tests from the Code Quality Dashboard.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>The dashboard now looks like this:<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: center; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/developer\/files\/codeQualityDashboardPost_4.png\" width = \"412\" height = \"648\" alt = \"codeQuality_postRun.png\" style = \"vertical-align: baseline; width: 412px; height: 648px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: center; '><span style=' font-style: italic;'>Code Quality Dashboard after tests have been run.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>You can use this information to assess the current state of your project. For example:<\/span><\/div><ul  style = 'margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif; font-size: 14px; '><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span>We have 1 suggestion identified by the Code Analyzer that we should review.<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span>Our statement coverage is 88%. This might mean that our code meets our company specified quality threshold.<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span>However, our MC\/DC is low so there are definite gaps in our testing despite the high statement coverage.<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span>Some of our tests are failing so we\u2019ll need to fix those.<\/span><\/li><li  style = 'margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap; '><span>17.4% of our requirements are not linked to tests in our project. Either they need to be linked to existing tests or we will need to write new tests.<\/span><\/li><\/ul><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>To view more detail on any of the sections in the Code Quality Dashboard, click on a given section and a dedicated report will be launched. For example, clicking on the Code Analyzer section will launch this report:<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: center; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/developer\/files\/codeQualityDashboardPost_5.png\" width = \"910\" height = \"477\" alt = \"codeQuality_codeAnalyzer_pre.png\" style = \"vertical-align: baseline; width: 910px; height: 477px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: center; '><span style=' font-style: italic;'>Code Analyzer report launched from the Code Quality Dashboard.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>I\u2019ll click the \u201cFix All\u201d button to fix the issue. At this point a banner appears in the Code Quality Dashboard notifying us that files in the project have changed so the dashboard needs refreshing.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: center; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/developer\/files\/codeQualityDashboardPost_6.png\" width = \"910\" height = \"509\" alt = \"codeQuality_codeAnalyzer_post.png\" style = \"vertical-align: baseline; width: 910px; height: 509px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: center; '><span style=' font-style: italic;'>Code Analyzer issue fixed and Code Quality Dashboard indicating that a refresh is required.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Once we click the \u201cUpdate Artifacts\u201d button in the banner, we then need to click a subsequent \u201cRefresh All\u201d button to refresh the metrics, and our dashboard is up to date again.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: center; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/developer\/files\/codeQualityDashboardPost_7.png\" width = \"566\" height = \"236\" alt = \"codeQuality_noIssues.png\" style = \"vertical-align: baseline; width: 566px; height: 236px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: center; '><span style=' font-style: italic;'>No more Code Analyzer issues following the update.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>In summary, the Code Quality Dashboard brings together key metrics about your project in one place, allowing you to make informed decisions. It serves as the centre point of a \u201cfind and fix\u201d workflow, allowing you to jump to more detailed views when you need them, and then coming back to the dashboard to view how your changes have affected the overall project status.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>In the next post I\u2019ll look at equivalence testing.<\/span><\/div>\r\n<\/div><script type=\"text\/javascript\">var css = ''; var head = document.head || document.getElementsByTagName('head')[0], style = document.createElement('style'); head.appendChild(style); style.type = 'text\/css'; if (style.styleSheet){ style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); }<\/script>","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/developer\/files\/codeQualityDashboardPost_4.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><p>This is the third instalment in my series on MATLAB Test. My previous posts introduced MATLAB Test and the Test Manager and the use of advanced coverage metrics. Today I\u2019m going to look at the Code... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/developer\/2023\/09\/18\/measuring-and-monitoring-code-quality\/\">read more >><\/a><\/p>","protected":false},"author":178,"featured_media":3122,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[42,44],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/developer\/wp-json\/wp\/v2\/posts\/3134"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/developer\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/developer\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/developer\/wp-json\/wp\/v2\/users\/178"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/developer\/wp-json\/wp\/v2\/comments?post=3134"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/developer\/wp-json\/wp\/v2\/posts\/3134\/revisions"}],"predecessor-version":[{"id":3137,"href":"https:\/\/blogs.mathworks.com\/developer\/wp-json\/wp\/v2\/posts\/3134\/revisions\/3137"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/developer\/wp-json\/wp\/v2\/media\/3122"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/developer\/wp-json\/wp\/v2\/media?parent=3134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/developer\/wp-json\/wp\/v2\/categories?post=3134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/developer\/wp-json\/wp\/v2\/tags?post=3134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}