{"id":160,"date":"2010-11-30T13:18:00","date_gmt":"2010-11-30T13:18:00","guid":{"rendered":"https:\/\/pagan-gerbil.net\/?p=160"},"modified":"2010-11-30T13:18:00","modified_gmt":"2010-11-30T13:18:00","slug":"learning-unit-testing-vi-code-coverage","status":"publish","type":"post","link":"https:\/\/www.pagan-gerbil.net\/?p=160","title":{"rendered":"Learning Unit Testing VI &#8211; Code Coverage"},"content":{"rendered":"<p>Before I get into finally finishing off that blasted page 10, I thought I\u2019d go through a code coverage run to see how I was doing. Test Driven Development, see, everything should be covered by a test.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto\" border=\"0\" alt=\"image\" src=\"https:\/\/pagan-gerbil.net\/wp-content\/uploads\/2017\/01\/image-2.png\" width=\"600\" height=\"54\"><\/p>\n<p>7.41% of the code is not covered by tests! I must be doing this wrong&#8230;<\/p>\n<p><a href=\"https:\/\/pagan-gerbil.net\/wp-content\/uploads\/2017\/01\/image_3-2.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image_3\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto\" border=\"0\" alt=\"image_3\" src=\"https:\/\/pagan-gerbil.net\/wp-content\/uploads\/2017\/01\/image_3_thumb.png\" width=\"600\" height=\"108\"><\/a><\/p>\n<p>Phew, that was a relief. Turns out all of that uncovered code is in the WrongPhaseException I created from the Exception snippit without thinking about it. Activating the code coverage colouring in the code shows me what I\u2019ve missed:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"image_4\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto\" border=\"0\" alt=\"image_4\" src=\"https:\/\/pagan-gerbil.net\/wp-content\/uploads\/2017\/01\/image_4.png\" width=\"600\" height=\"169\"><\/p>\n<p>Because I only use one constructor out of a possible four, it counts as only 25% coverage and brings my average code coverage way down.<\/p>\n<p>If I was to remove all those extra constructors (and leave them to the default Exception behaviour), would it improve my code coverage score?<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"image_5\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto\" border=\"0\" alt=\"image_5\" src=\"https:\/\/pagan-gerbil.net\/wp-content\/uploads\/2017\/01\/image_5.png\" width=\"600\" height=\"121\"><\/p>\n<p>Absolutely. It might be a bit like cheating (those methods are still not covered by tests), but since they\u2019re core parts of the framework it doesn\u2019t feel necessary to me. Short and sweet, on to part VII!<\/p>\n<p><em>This is a learning project I am documenting in order to teach myself TDD and unit testing &#8211; as I publish this, I have already written many parts in advance but I want to know what I\u2019m doing wrong! If you see improvements or corrections, either to the code or the process, please leave a comment and let me know! Introduction to this project can be found <a href=\"https:\/\/pagan-gerbil.net\/?p=106\">here<\/a>.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Before I get into finally finishing off that blasted page 10, I thought I\u2019d go through a code coverage run to see how I was doing. Test Driven Development, see, everything should be covered by a test. 7.41% of the code is not covered by tests! I must be doing this wrong&#8230; Phew, that was &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.pagan-gerbil.net\/?p=160\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Learning Unit Testing VI &#8211; Code Coverage&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[43,62,63,64],"series":[73],"_links":{"self":[{"href":"https:\/\/www.pagan-gerbil.net\/index.php?rest_route=\/wp\/v2\/posts\/160"}],"collection":[{"href":"https:\/\/www.pagan-gerbil.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pagan-gerbil.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pagan-gerbil.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pagan-gerbil.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=160"}],"version-history":[{"count":0,"href":"https:\/\/www.pagan-gerbil.net\/index.php?rest_route=\/wp\/v2\/posts\/160\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.pagan-gerbil.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pagan-gerbil.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pagan-gerbil.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=160"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.pagan-gerbil.net\/index.php?rest_route=%2Fwp%2Fv2%2Fseries&post=160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}