{"id":49569,"date":"2025-06-01T23:53:48","date_gmt":"2025-06-01T23:53:48","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=49569"},"modified":"2026-02-21T07:29:14","modified_gmt":"2026-02-21T07:29:14","slug":"code-coverage-tutorials-main-types-of-code-coverage-metrics","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/code-coverage-tutorials-main-types-of-code-coverage-metrics\/","title":{"rendered":"Code Coverage Tutorials: Main types of code coverage metrics"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"951\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2025\/06\/image-1024x951.png\" alt=\"\" class=\"wp-image-49570\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2025\/06\/image-1024x951.png 1024w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2025\/06\/image-300x279.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2025\/06\/image-768x713.png 768w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2025\/06\/image.png 1268w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Here\u2019s a comprehensive list of the <strong>main types of code coverage metrics<\/strong> used in software testing, ranging from basic to advanced:<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\">\n\n\n\n<h2 class=\"wp-block-heading\">\u2705 <strong>1. C0: Line Coverage (Statement Coverage)<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>What it measures<\/strong>: Whether each line of code has been executed.<\/li>\n\n\n\n<li><strong>Goal<\/strong>: Make sure all lines run at least once.<\/li>\n\n\n\n<li><strong>Example<\/strong>: <code>if is_valid(user): # Covered if condition is evaluated send_email(user) # Covered if executed<\/code><\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\">\n\n\n\n<h2 class=\"wp-block-heading\">\u2705 <strong>2. C1: Branch Coverage (Decision Coverage \/ Condition Coverage)<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>What it measures<\/strong>: Whether each decision (like <code>if<\/code>, <code>else<\/code>, <code>case<\/code>, loop conditions) has been evaluated both <code>true<\/code> and <code>false<\/code>.<\/li>\n\n\n\n<li><strong>Goal<\/strong>: Ensure all branches of control structures are tested.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\">\n\n\n\n<h2 class=\"wp-block-heading\">\u2705 <strong>3. C2: Path Coverage<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>What it measures<\/strong>: Whether all possible execution <strong>paths<\/strong> through a function are executed.<\/li>\n\n\n\n<li><strong>Goal<\/strong>: Ensure every unique route through the code is tested.<\/li>\n\n\n\n<li><strong>Note<\/strong>: Path coverage grows exponentially with complexity, so it\u2019s often impractical for large methods.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\">\n\n\n\n<h2 class=\"wp-block-heading\">\u2705 <strong>4. Condition Coverage (or Predicate Coverage)<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>What it measures<\/strong>: Whether each <strong>boolean sub-expression<\/strong> in a decision has been evaluated to both <code>true<\/code> and <code>false<\/code>.<\/li>\n\n\n\n<li><strong>Example<\/strong>: <code>if (A &amp;&amp; B)<\/code>\n<ul class=\"wp-block-list\">\n<li>You must test:\n<ul class=\"wp-block-list\">\n<li>A = true, B = false<\/li>\n\n\n\n<li>A = false, B = true<\/li>\n\n\n\n<li>A = true, B = true<\/li>\n\n\n\n<li>A = false, B = false<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\">\n\n\n\n<h2 class=\"wp-block-heading\">\u2705 <strong>5. Modified Condition\/Decision Coverage (MC\/DC)<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>What it measures<\/strong>: Whether each condition in a decision has been shown to independently affect the outcome of that decision.<\/li>\n\n\n\n<li><strong>Used in<\/strong>: Aviation, automotive, medical systems (critical systems testing).<\/li>\n\n\n\n<li><strong>Example<\/strong>:\n<ul class=\"wp-block-list\">\n<li>For <code>if (A &amp;&amp; B)<\/code>, test cases must show that toggling <code>A<\/code> while keeping <code>B<\/code> fixed changes the decision result\u2014and vice versa.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\">\n\n\n\n<h2 class=\"wp-block-heading\">\u2705 <strong>6. Function Coverage<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>What it measures<\/strong>: Whether each function or method is called during execution.<\/li>\n\n\n\n<li><strong>Useful for<\/strong>: High-level view, especially in unit testing.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\">\n\n\n\n<h2 class=\"wp-block-heading\">\u2705 <strong>7. Loop Coverage<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>What it measures<\/strong>: Whether loops are executed:\n<ul class=\"wp-block-list\">\n<li>Zero times (e.g. empty loop case)<\/li>\n\n\n\n<li>One time<\/li>\n\n\n\n<li>Multiple times<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Example<\/strong>: <code>for i in range(n): print(i)<\/code>\n<ul class=\"wp-block-list\">\n<li>Test with <code>n = 0<\/code>, <code>n = 1<\/code>, and <code>n &gt; 1<\/code>.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\">\n\n\n\n<h2 class=\"wp-block-heading\">\u2705 <strong>8. Call Coverage<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>What it measures<\/strong>: Whether function <strong>calls<\/strong> between modules\/classes are exercised.<\/li>\n\n\n\n<li><strong>Used for<\/strong>: Integration-level or system-level tests.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\">\n\n\n\n<h2 class=\"wp-block-heading\">\u2705 <strong>9. Exception Coverage<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>What it measures<\/strong>: Whether exception-handling code is covered (e.g. <code>try<\/code>, <code>catch<\/code>, <code>finally<\/code> blocks).<\/li>\n\n\n\n<li><strong>Goal<\/strong>: Ensure error paths are tested.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\">\n\n\n\n<h2 class=\"wp-block-heading\">\u2705 <strong>10. Data Flow Coverage<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>What it measures<\/strong>: Tracks variables to see:\n<ul class=\"wp-block-list\">\n<li>Where they&#8217;re defined (assigned),<\/li>\n\n\n\n<li>Where they&#8217;re used (referenced),<\/li>\n\n\n\n<li>And whether they&#8217;re used correctly.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Types include<\/strong>:\n<ul class=\"wp-block-list\">\n<li>Definition-use (DU) chains<\/li>\n\n\n\n<li>All-defs, all-uses, all-paths<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\">\n\n\n\n<h2 class=\"wp-block-heading\">\u2705 <strong>11. Toggle Condition Coverage<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>What it measures<\/strong>: Ensures that each condition&#8217;s change (toggle from true to false or vice versa) influences the outcome at least once.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\">\n\n\n\n<h2 class=\"wp-block-heading\">Summary Table<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Metric<\/th><th>Focus Area<\/th><th>Practical Use<\/th><\/tr><\/thead><tbody><tr><td><strong>C0 (Line Coverage)<\/strong><\/td><td>Statements<\/td><td>Basic test coverage<\/td><\/tr><tr><td><strong>C1 (Branch Coverage)<\/strong><\/td><td>Conditions\/branches<\/td><td>Ensures <code>if\/else<\/code> tested<\/td><\/tr><tr><td><strong>C2 (Path Coverage)<\/strong><\/td><td>Execution paths<\/td><td>Exhaustive, mostly theoretical<\/td><\/tr><tr><td><strong>Condition Coverage<\/strong><\/td><td>Boolean sub-conditions<\/td><td>Logic safety<\/td><\/tr><tr><td><strong>MC\/DC<\/strong><\/td><td>Independence of conditions<\/td><td>Safety-critical industries<\/td><\/tr><tr><td><strong>Function Coverage<\/strong><\/td><td>Methods\/functions<\/td><td>High-level view<\/td><\/tr><tr><td><strong>Loop Coverage<\/strong><\/td><td>Loop bodies<\/td><td>Loop logic correctness<\/td><\/tr><tr><td><strong>Call Coverage<\/strong><\/td><td>Inter-module function calls<\/td><td>Integration testing<\/td><\/tr><tr><td><strong>Exception Coverage<\/strong><\/td><td>Error-handling code<\/td><td>Robustness validation<\/td><\/tr><tr><td><strong>Data Flow Coverage<\/strong><\/td><td>Variable definition\/use paths<\/td><td>Detects potential bugs or dead code<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\">\n\n\n\n<p>Would you like a diagram or sample report showing how these look in real tools like <strong>SonarCloud<\/strong>, <strong>JaCoCo<\/strong>, or <strong>Istanbul<\/strong>?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here\u2019s a comprehensive list of the main types of code coverage metrics used in software testing, ranging from basic to advanced: \u2705 1. C0: Line Coverage (Statement Coverage) \u2705 2. C1: Branch Coverage (Decision Coverage \/ Condition Coverage) \u2705 3. C2: Path Coverage \u2705 4. Condition Coverage (or Predicate Coverage) \u2705 5. Modified Condition\/Decision Coverage&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[2],"tags":[],"class_list":["post-49569","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/49569","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=49569"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/49569\/revisions"}],"predecessor-version":[{"id":58997,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/49569\/revisions\/58997"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=49569"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=49569"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=49569"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}