{"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":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.8 - aioseo.com -->\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"rocker8942\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/moneystock.net\/wp_e\/2021\/05\/07\/when-test-driven-development-goes-wrong\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.8\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Joe&#039;s Happy Life | Be positive, have fun\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"When Test Driven Development Goes Wrong | Joe&#039;s Happy Life\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/moneystock.net\/wp_e\/2021\/05\/07\/when-test-driven-development-goes-wrong\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2021-05-07T13:32:09+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2021-05-07T13:32:09+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"When Test Driven Development Goes Wrong | Joe&#039;s Happy Life\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/moneystock.net\\\/wp_e\\\/2021\\\/05\\\/07\\\/when-test-driven-development-goes-wrong\\\/#article\",\"name\":\"When Test Driven Development Goes Wrong | Joe's Happy Life\",\"headline\":\"When Test Driven Development Goes Wrong\",\"author\":{\"@id\":\"https:\\\/\\\/moneystock.net\\\/wp_e\\\/author\\\/rocker8942\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/moneystock.net\\\/wp_e\\\/#organization\"},\"datePublished\":\"2021-05-07T23:32:09+08:00\",\"dateModified\":\"2021-05-07T23:32:09+08:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/moneystock.net\\\/wp_e\\\/2021\\\/05\\\/07\\\/when-test-driven-development-goes-wrong\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/moneystock.net\\\/wp_e\\\/2021\\\/05\\\/07\\\/when-test-driven-development-goes-wrong\\\/#webpage\"},\"articleSection\":\"Architecture, C#, TDD, Test Driven Development, English\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/moneystock.net\\\/wp_e\\\/2021\\\/05\\\/07\\\/when-test-driven-development-goes-wrong\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/moneystock.net\\\/wp_e#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/moneystock.net\\\/wp_e\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/moneystock.net\\\/wp_e\\\/category\\\/c\\\/#listItem\",\"name\":\"C#\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/moneystock.net\\\/wp_e\\\/category\\\/c\\\/#listItem\",\"position\":2,\"name\":\"C#\",\"item\":\"https:\\\/\\\/moneystock.net\\\/wp_e\\\/category\\\/c\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/moneystock.net\\\/wp_e\\\/2021\\\/05\\\/07\\\/when-test-driven-development-goes-wrong\\\/#listItem\",\"name\":\"When Test Driven Development Goes Wrong\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/moneystock.net\\\/wp_e#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/moneystock.net\\\/wp_e\\\/2021\\\/05\\\/07\\\/when-test-driven-development-goes-wrong\\\/#listItem\",\"position\":3,\"name\":\"When Test Driven Development Goes Wrong\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/moneystock.net\\\/wp_e\\\/category\\\/c\\\/#listItem\",\"name\":\"C#\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/moneystock.net\\\/wp_e\\\/#organization\",\"name\":\"Joe's Happy Life\",\"description\":\"Be positive, have fun\",\"url\":\"https:\\\/\\\/moneystock.net\\\/wp_e\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/moneystock.net\\\/wp_e\\\/author\\\/rocker8942\\\/#author\",\"url\":\"https:\\\/\\\/moneystock.net\\\/wp_e\\\/author\\\/rocker8942\\\/\",\"name\":\"rocker8942\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/moneystock.net\\\/wp_e\\\/2021\\\/05\\\/07\\\/when-test-driven-development-goes-wrong\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d00fcc2c7b0eaab40443e28428a4429ab4a95e12086262d902988f448d76b128?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"rocker8942\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/moneystock.net\\\/wp_e\\\/2021\\\/05\\\/07\\\/when-test-driven-development-goes-wrong\\\/#webpage\",\"url\":\"https:\\\/\\\/moneystock.net\\\/wp_e\\\/2021\\\/05\\\/07\\\/when-test-driven-development-goes-wrong\\\/\",\"name\":\"When Test Driven Development Goes Wrong | Joe's Happy Life\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/moneystock.net\\\/wp_e\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/moneystock.net\\\/wp_e\\\/2021\\\/05\\\/07\\\/when-test-driven-development-goes-wrong\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/moneystock.net\\\/wp_e\\\/author\\\/rocker8942\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/moneystock.net\\\/wp_e\\\/author\\\/rocker8942\\\/#author\"},\"datePublished\":\"2021-05-07T23:32:09+08:00\",\"dateModified\":\"2021-05-07T23:32:09+08:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/moneystock.net\\\/wp_e\\\/#website\",\"url\":\"https:\\\/\\\/moneystock.net\\\/wp_e\\\/\",\"name\":\"Joe's Happy Life\",\"description\":\"Be positive, have fun\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/moneystock.net\\\/wp_e\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"When Test Driven Development Goes Wrong | Joe's Happy Life","description":"","canonical_url":"https:\/\/moneystock.net\/wp_e\/2021\/05\/07\/when-test-driven-development-goes-wrong\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/moneystock.net\/wp_e\/2021\/05\/07\/when-test-driven-development-goes-wrong\/#article","name":"When Test Driven Development Goes Wrong | Joe's Happy Life","headline":"When Test Driven Development Goes Wrong","author":{"@id":"https:\/\/moneystock.net\/wp_e\/author\/rocker8942\/#author"},"publisher":{"@id":"https:\/\/moneystock.net\/wp_e\/#organization"},"datePublished":"2021-05-07T23:32:09+08:00","dateModified":"2021-05-07T23:32:09+08:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/moneystock.net\/wp_e\/2021\/05\/07\/when-test-driven-development-goes-wrong\/#webpage"},"isPartOf":{"@id":"https:\/\/moneystock.net\/wp_e\/2021\/05\/07\/when-test-driven-development-goes-wrong\/#webpage"},"articleSection":"Architecture, C#, TDD, Test Driven Development, English"},{"@type":"BreadcrumbList","@id":"https:\/\/moneystock.net\/wp_e\/2021\/05\/07\/when-test-driven-development-goes-wrong\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/moneystock.net\/wp_e#listItem","position":1,"name":"Home","item":"https:\/\/moneystock.net\/wp_e","nextItem":{"@type":"ListItem","@id":"https:\/\/moneystock.net\/wp_e\/category\/c\/#listItem","name":"C#"}},{"@type":"ListItem","@id":"https:\/\/moneystock.net\/wp_e\/category\/c\/#listItem","position":2,"name":"C#","item":"https:\/\/moneystock.net\/wp_e\/category\/c\/","nextItem":{"@type":"ListItem","@id":"https:\/\/moneystock.net\/wp_e\/2021\/05\/07\/when-test-driven-development-goes-wrong\/#listItem","name":"When Test Driven Development Goes Wrong"},"previousItem":{"@type":"ListItem","@id":"https:\/\/moneystock.net\/wp_e#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/moneystock.net\/wp_e\/2021\/05\/07\/when-test-driven-development-goes-wrong\/#listItem","position":3,"name":"When Test Driven Development Goes Wrong","previousItem":{"@type":"ListItem","@id":"https:\/\/moneystock.net\/wp_e\/category\/c\/#listItem","name":"C#"}}]},{"@type":"Organization","@id":"https:\/\/moneystock.net\/wp_e\/#organization","name":"Joe's Happy Life","description":"Be positive, have fun","url":"https:\/\/moneystock.net\/wp_e\/"},{"@type":"Person","@id":"https:\/\/moneystock.net\/wp_e\/author\/rocker8942\/#author","url":"https:\/\/moneystock.net\/wp_e\/author\/rocker8942\/","name":"rocker8942","image":{"@type":"ImageObject","@id":"https:\/\/moneystock.net\/wp_e\/2021\/05\/07\/when-test-driven-development-goes-wrong\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/d00fcc2c7b0eaab40443e28428a4429ab4a95e12086262d902988f448d76b128?s=96&d=mm&r=g","width":96,"height":96,"caption":"rocker8942"}},{"@type":"WebPage","@id":"https:\/\/moneystock.net\/wp_e\/2021\/05\/07\/when-test-driven-development-goes-wrong\/#webpage","url":"https:\/\/moneystock.net\/wp_e\/2021\/05\/07\/when-test-driven-development-goes-wrong\/","name":"When Test Driven Development Goes Wrong | Joe's Happy Life","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/moneystock.net\/wp_e\/#website"},"breadcrumb":{"@id":"https:\/\/moneystock.net\/wp_e\/2021\/05\/07\/when-test-driven-development-goes-wrong\/#breadcrumblist"},"author":{"@id":"https:\/\/moneystock.net\/wp_e\/author\/rocker8942\/#author"},"creator":{"@id":"https:\/\/moneystock.net\/wp_e\/author\/rocker8942\/#author"},"datePublished":"2021-05-07T23:32:09+08:00","dateModified":"2021-05-07T23:32:09+08:00"},{"@type":"WebSite","@id":"https:\/\/moneystock.net\/wp_e\/#website","url":"https:\/\/moneystock.net\/wp_e\/","name":"Joe's Happy Life","description":"Be positive, have fun","inLanguage":"en-US","publisher":{"@id":"https:\/\/moneystock.net\/wp_e\/#organization"}}]},"og:locale":"en_US","og:site_name":"Joe's Happy Life | Be positive, have fun","og:type":"article","og:title":"When Test Driven Development Goes Wrong | Joe's Happy Life","og:url":"https:\/\/moneystock.net\/wp_e\/2021\/05\/07\/when-test-driven-development-goes-wrong\/","article:published_time":"2021-05-07T13:32:09+00:00","article:modified_time":"2021-05-07T13:32:09+00:00","twitter:card":"summary","twitter:title":"When Test Driven Development Goes Wrong | Joe's Happy Life"},"aioseo_meta_data":{"post_id":"1232","title":null,"description":null,"keywords":[],"keyphrases":{"focus":[],"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":{"id":"aioseo-article-63a86783b2703","slug":"article","graphName":"Article","label":"Article","properties":{"type":"BlogPosting","name":"#post_title","headline":"#post_title","description":"#post_excerpt","image":"","keywords":"","author":{"name":"#author_name","url":"#author_url"},"dates":{"include":true,"datePublished":"","dateModified":""}}},"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":"{\"article\":{\"articleType\":\"BlogPosting\"},\"course\":{\"name\":\"\",\"description\":\"\",\"provider\":\"\"},\"faq\":{\"pages\":[]},\"product\":{\"reviews\":[]},\"recipe\":{\"ingredients\":[],\"instructions\":[],\"keywords\":[]},\"software\":{\"reviews\":[],\"operatingSystems\":[]},\"webPage\":{\"webPageType\":\"WebPage\"}}","pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","local_seo":{"locations":{"business":{"name":"","businessType":"","image":"","areaServed":"","urls":{"website":"","aboutPage":"","contactPage":""},"address":{"streetLine1":"","streetLine2":"","zipCode":"","city":"","state":"","country":"","addressFormat":"#streetLineOne\n#streetLineTwo\n#city, #state #zipCode"},"contact":{"phone":"","email":"","fax":""},"ids":{"vat":"","tax":"","chamberOfCommerce":""},"payment":{"priceRange":"","currenciesAccepted":"","methods":""}}},"openingHours":{"useDefaults":true,"show":true,"alwaysOpen":false,"use24hFormat":false,"timezone":"","labels":{"closed":"","alwaysOpen":""},"days":{"monday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"tuesday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"wednesday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"thursday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"friday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"saturday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"sunday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"}}}},"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-05-07 13:07:12","updated":"2025-06-03 23:55:09","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/moneystock.net\/wp_e\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/moneystock.net\/wp_e\/category\/c\/\" title=\"C#\">C#<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tWhen Test Driven Development Goes Wrong\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/moneystock.net\/wp_e"},{"label":"C#","link":"https:\/\/moneystock.net\/wp_e\/category\/c\/"},{"label":"When Test Driven Development Goes Wrong","link":"https:\/\/moneystock.net\/wp_e\/2021\/05\/07\/when-test-driven-development-goes-wrong\/"}],"_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}]}}