{"id":3251,"date":"2015-03-04T13:00:09","date_gmt":"2015-03-04T13:00:09","guid":{"rendered":"http:\/\/writeasync.net\/?p=3251"},"modified":"2015-03-04T04:43:04","modified_gmt":"2015-03-04T04:43:04","slug":"gratuitous-complications-unit-test-fault-injection","status":"publish","type":"post","link":"http:\/\/writeasync.net\/?p=3251","title":{"rendered":"Gratuitous complications: unit test fault injection"},"content":{"rendered":"<p>Sometimes things don&#8217;t need to be complicated. I would go so far to say <em>most of the time<\/em> things don&#8217;t need to be complicated. In <a href=\"https:\/\/twitter.com\/unclebobmartin\/status\/555034386929025024\">the words of Uncle Bob Martin<\/a>, &#8220;it is the software engineer&#8217;s job to make tough problems easy to solve.&#8221; Here is a quick example of a gratuitous complication I see often enough to warrant a cautionary post.<\/p>\n<p>In a <a href=\"http:\/\/writeasync.net\/?p=3131\">previous post<\/a> I discussed fault injection, specifically of the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Black-box_testing\">black box<\/a> kind. Given how useful fault injection can be in getting holistic testing of error handling paths, it seems natural to want to make this practice ubiquitous. Indeed you&#8217;ll see <a href=\"https:\/\/developer.jboss.org\/wiki\/FaultInjectionTestingWithByteman\">many<\/a> <a href=\"https:\/\/www.rcis.aist.go.jp\/files\/events\/2010\/0514-ja\/enforcer_poster.pdf\">links<\/a> <a href=\"http:\/\/blitiri.com.ar\/p\/libfiu\/\">on<\/a> <a href=\"https:\/\/josefbetancourt.wordpress.com\/2011\/11\/13\/exception-verification-aop\/\">the<\/a> <a href=\"http:\/\/www.cs.colostate.edu\/~bieman\/Pubs\/issre96preprint.pdf\">web<\/a> about applying fault injection tools and libraries to what would ostensibly be unit tests.<\/p>\n<p>Presuming you already have unit tests and a relatively testable design, you are already 90% of way to having a fast and reliable mechanism for deterministic fault injection. It is called&#8230; programming a <a href=\"http:\/\/xunitpatterns.com\/Test%20Double.html\">test double<\/a> to throw an exception and then verifying the exception is handled correctly. (The lack of a catchy name does make marketing this approach harder, but don&#8217;t be dissuaded.) By all means, continue to use heavier fault injection machinery to find gaps in your design &#8212; consider these tools like the <a href=\"\nhttp:\/\/en.wikipedia.org\/wiki\/Spackling_paste\">spackling paste<\/a> to the cracks in your software walls. Just don&#8217;t paint your whole house with them.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes things don&#8217;t need to be complicated. I would go so far to say most of the time things don&#8217;t need to be complicated. In the words of Uncle Bob Martin, &#8220;it is the software engineer&#8217;s job to make tough&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[91,41,51],"tags":[],"class_list":["post-3251","post","type-post","status-publish","format-standard","hentry","category-design","category-tdd","category-testing"],"_links":{"self":[{"href":"http:\/\/writeasync.net\/index.php?rest_route=\/wp\/v2\/posts\/3251","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/writeasync.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/writeasync.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/writeasync.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/writeasync.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3251"}],"version-history":[{"count":0,"href":"http:\/\/writeasync.net\/index.php?rest_route=\/wp\/v2\/posts\/3251\/revisions"}],"wp:attachment":[{"href":"http:\/\/writeasync.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/writeasync.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3251"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/writeasync.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}