{"id":339,"date":"2013-05-17T12:00:23","date_gmt":"2013-05-17T12:00:23","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/2013\/05\/17\/what-is-code-coverage-and-why-code-coverage\/"},"modified":"2017-12-25T01:05:10","modified_gmt":"2017-12-25T01:05:10","slug":"what-is-code-coverage-and-why-code-coverage","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/what-is-code-coverage-and-why-code-coverage\/","title":{"rendered":"What is Code Coverage and Why Code Coverage?"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3760 aligncenter\" src=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2013\/05\/code-coverage.png\" alt=\"code-coverage\" width=\"600\" height=\"400\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2013\/05\/code-coverage.png 600w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2013\/05\/code-coverage-300x200.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p><strong>What is Code Coverage<\/strong><br \/>\nCode Coverage is an important measurement in Software Quality Engineering. While Software testing ensures correctness of the applications, a metric is required to track the What is Code Coverage Code Coverage is an important measurement in Software Quality Engineering. While Software testing ensures correctness of the applications, a metric is required to track the completeness and effectiveness of the testing undertaken. Code Coverage helps achieve reliable quality through identifying untested areas of the application.<\/p>\n<p><strong>Why Code Coverage<\/strong><br \/>\nSoftware testing is a challenging function. The testers need to ensure complete functional and non-functional correctness of the product. Considering the complex workflows and use cases of modern day applications, the number of unique cases that the software can be used often run into millions, which is not feasible to be covered under testing exercise. The testers thus need to<br \/>\n&#8211; While Planning Tests<br \/>\no Ensure covering all workflows in terms of decision trees in the code<br \/>\no Ensure covering all data values \u2013 by identifying patterns rather covering millions of values<br \/>\n&#8211; While testing<br \/>\no Ensuring the testing is completely exercising the whole application with planned and exploratory tests.<\/p>\n<p>At the end of testing, the decision to stop testing and release the product still remains subjective, based on the presence or absence of bugs, inflow of new bugs, success rate of each test cycle, confidence rating of the testers or users, etc. Whereas the definitive metric of quantifying how much of the application was really tested, is missed.<\/p>\n<p>Code Coverage is measured as quantification of application code exercised by the testing activities. Code Coverage can be measured at various levels \u2013 in terms of programming language constructs \u2013 Packages, Classes, Methods, Branches or in terms of physical artifacts &#8211; Folders, Files and Lines. For Eg. A Line Coverage metric of 67% means the testing exercised 67% of all executable statements of the application. A Code Coverage metric usually is accompanied by Code Coverage Analysis Report \u2013 which helps identify the un-tested part of the application code, thereby giving the testers early inputs for complete testing.<\/p>\n<p><strong>Benefits of Code Coverage<\/strong><\/p>\n<ul>\n<li>Objective Indicator of Test Coverage of application code<\/li>\n<li>Pointers to uncovered Packages \/ Classes \/ Methods \/ Branches<\/li>\n<li>Pointers to uncovered Folders \/ Files \/ Lines<\/li>\n<li>Drill down to untested part of source code and devise new tests<\/li>\n<li>Early Indicator for Testing Quality and Fixing it by adding new tests.<\/li>\n<li>Remove redundancy in testing<\/li>\n<li>Increased Confidence for Releases<\/li>\n<\/ul>\n<p><strong>Test Your Test<\/strong><\/p>\n<p><strong>Typical Emotional Storyboard<\/strong><\/p>\n<ul>\n<li>Write Some code! Happy!<\/li>\n<li>Does it work? Sad!<\/li>\n<li>Write some test! Happy!<\/li>\n<li>Do they really test the code? Sad!<\/li>\n<li>Measure the Code Coverage! Happy!<\/li>\n<\/ul>\n<p><strong>Coverage Measurement<\/strong><\/p>\n<ol>\n<li>Shows Which line of code are executed<\/li>\n<li>How much of your code is covered by your tests?<\/li>\n<li>Your tests test your product<\/li>\n<li>Coverage testing tests your tests<\/li>\n<\/ol>\n<p><strong>Goal<\/strong><\/p>\n<ul>\n<li>100%<\/li>\n<li>Coverage Ideal<\/li>\n<li>Not Always possible<\/li>\n<li>Can be expensive to achieve<\/li>\n<li>Design for testability<\/li>\n<\/ul>\n<p><strong>Good: Write more tests<\/strong><br \/>\nOnly way to truly increase code coverage<\/p>\n<p><strong>Bad<\/strong><br \/>\nExcluding Code to boost Coverage<\/p>\n<p><strong>Types of Coverage<\/strong><\/p>\n<ol>\n<li>Statement Coverage<\/li>\n<li>Branch Coverage<\/li>\n<li>Path Coverage<\/li>\n<li>Loop Path Coverage<\/li>\n<li>Data \u2013 driven Code<\/li>\n<li>Complex Conditionals<\/li>\n<li>Hidden Branches<\/li>\n<\/ol>\n<p><strong>How; &#8211; Coverage Tools<\/strong><\/p>\n<ol>\n<li>Clover<\/li>\n<li>Cobertura<\/li>\n<li>Emma<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>What is Code Coverage Code Coverage is an important measurement in Software Quality Engineering. While Software testing ensures correctness of the applications, a metric is required to track the What&#8230; <\/p>\n","protected":false},"author":1,"featured_media":3760,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[62],"tags":[1729,2330,1003,610,1040,2331,2333,2332,1734,779,670,2328,842,2329],"class_list":["post-339","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-code-analysis","tag-advantages","tag-benefits-of-code-coverage","tag-code","tag-code-coverage","tag-coverage","tag-coverage-tools","tag-quality-analysis","tag-software-quality","tag-test-coverage","tag-testing","tag-what","tag-what-is-code-coverage","tag-why","tag-why-code-coverage"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/339","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=339"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/339\/revisions"}],"predecessor-version":[{"id":3761,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/339\/revisions\/3761"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/3760"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}