{"id":1232,"date":"2021-05-07T23:32:09","date_gmt":"2021-05-07T13:32:09","guid":{"rendered":"https:\/\/www.moneystock.net\/wp_e\/?p=1232"},"modified":"2021-05-07T23:32:09","modified_gmt":"2021-05-07T13:32:09","slug":"when-test-driven-development-goes-wrong","status":"publish","type":"post","link":"https:\/\/moneystock.net\/wp_e\/2021\/05\/07\/when-test-driven-development-goes-wrong\/","title":{"rendered":"When Test Driven Development Goes Wrong"},"content":{"rendered":"<p>When you feel TDD is difficult when you first started TDD, that might sign that there are improvements to make in the design.<\/p>\n<p>There are 5 common anti-patterns.<\/p>\n<ol>\n<li>The Liar<br \/>\nPasses all tests with no useful assertions, which could be caused by chasing test coverage.<br \/>\n=&gt; Write the test first, which fails with a purpose.<\/li>\n<li>Excessive Setup<br \/>\nTest and Code are highly coupled. Hard to maintain.<br \/>\n=&gt; Improve Abstraction and Separation of Concerns. Write Test first.<\/li>\n<li>The Giant<br \/>\nMany lines of code and many assertions which caused by writing the code first before writing testing. This isn&#8217;t easy to understand.<br \/>\n=&gt; Decomposed into multiple test cases.<\/li>\n<li>The Mockery<br \/>\nUse so many mocks, which is similar to the excessive setup.<br \/>\n=&gt; Review design of code. The same solution as #2.<\/li>\n<li>The inspector<br \/>\nViolate encapsulation to make assertions, which can be caused by poor dependency injection.<br \/>\n=&gt; Never compromise encapsulation for testing. Design for testability.<\/li>\n<\/ol>\n<p>In summary, to practice TDD correctly, write a test first, which will help design the code testable.<\/p>\n<p>&nbsp;<\/p>\n<p>reference: <a href=\"https:\/\/www.youtube.com\/watch?v=-4Ybn0Cz2oU\">GOTO 2021 \u2022 When Test Driven Development Goes Wrong \u2022 Dave Farley<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you feel TDD is difficult when you first started TDD, that might sign that there are improvements to make in the design. There are 5 common anti-patterns. The Liar Passes all tests with no useful assertions, which could be caused by chasing test coverage. =&gt; Write the test first, which fails with a purpose.&hellip; <a class=\"more-link\" href=\"https:\/\/moneystock.net\/wp_e\/2021\/05\/07\/when-test-driven-development-goes-wrong\/\">Continue reading <span class=\"screen-reader-text\">When Test Driven Development Goes Wrong<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[606,548],"tags":[622,624],"class_list":["post-1232","post","type-post","status-publish","format-standard","hentry","category-architecture","category-c","tag-tdd","tag-test-driven-development","entry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/posts\/1232","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/comments?post=1232"}],"version-history":[{"count":1,"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/posts\/1232\/revisions"}],"predecessor-version":[{"id":1233,"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/posts\/1232\/revisions\/1233"}],"wp:attachment":[{"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/media?parent=1232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/categories?post=1232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/tags?post=1232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}