Premature Passes: Why You Might Be Getting Green on Red



Red, green, refactor. The first step in the test-driven development (TDD) cycle is to ensure that your newly-written test fails before you try to write the code to make it pass. But why expend the effort and waste the time to run the tests? If you're following TDD, you write each new test for code that doesn't yet exist, and so it shouldn't pass.

But reality says it will happen--you will undoubtedly get a green bar when you expect a red bar from time to time. (We call this occurrence a premature pass.) Understanding one of the many reasons why you got a premature pass might help save you precious time.
  • Running the wrong tests. This smack-your-forehead event occurs when you think you were including your new test in the run, but were not, for one of myriad reasons. Maybe you forgot to compile it, link in the new test, ran the wrong suite, disabled the new test, filtered it out, or coded it improperly so that the tool didn't recognize it as a legitimate test. Suggestion: Always know your current test count, and ensure that your new test causes it to increment.
  • Testing the wrong code. You might have a premature pass for some of the same reasons as "running the wrong tests," such as failure to compile (in which case the "wrong code" that you're running is the last compiled version). Perhaps the build failed and you thought it passed, or your classpath is picking up a different version. More insidiously, if you're mucking with test doubles, your test might not be exercising the class implementation that you think it is (polymorphism can be a tricky beast). Suggestion: Throw an exception as the first line of code you think you're hitting, and re-run the tests.
  • Unfortunate test specification. Sometimes you mistakenly assert the wrong thing, and it happens to match what the system currently does. I recently coded an assertTrue where I meant assertFalse, and spent a few minutes scratching my head when the test passed. Suggestion: Re-read (or have someone else read) your test to ensure it specifies the proper behavior.
  • Invalid assumptions about the system. If you get a premature pass, you know your test is recognized and it's exercising the right code, and you've re-read the test... perhaps the behavior already exists in the system. Your test assumed that the behavior wasn't in the system, and following the process of TDD proved your assumption wrong. Suggestion: Stop and analyze your system, perhaps adding characterization tests, to fully understand how it behaves.
  • Suboptimal test order. As you are test-driving a solution, you're attempting to take the smallest possible incremental steps to grow behavior. Sometimes you'll choose a less-than-optimal sequence. You subsequently get a premature pass because the prior implementation unavoidably grew out a more robust solution than desired. Suggestions: Consider starting over and seeking a different sequence with smaller increments. Try to apply Uncle Bob's Transformation Priority Premise (TPP).
  • Linked production code. If you are attempting to devise an API to be consumed by multiple clients, you'll often introduce convenience methods such as isEmpty (which inquires about the size to determine its answer). These convenience methods necessarily duplicate code. If you try to assert against isEmpty every time you assert against size, you'll get premature passes. Suggestions: Create tests that document the link from the convenience method to the core functionality, demonstrating them. Or combine the related assertions into a single custom assertion (or helper method).
  • Overcoding. A different form of "invalid assumptions about the system," you overcode when you supply more of an implementation than necessary while test-driving. This is a hard lesson of TDD--to supply no more code or data structure than necessary when getting a test to pass. Suggestion: Hard lessons are best learned with dramatic solutions. Discard your bloated solution and try again. It'll be better, we promise.
  • Testing for confidence. On occasion, you'll know when you think a test will generate a premature pass. There's nothing wrong with writing a couple additional tests: "I wonder if it works for this edge case," particularly if those tests give you confidence, but technically you have stepped outside the realm of TDD and moved into the realm of TAD (test-after development). Suggestions: Don't hesitate to write more tests to give you confidence, but you should generally have a good idea of whether they will pass or fail before you run them.
Two key things to remember:
  • Never skip running the tests to ensure you get a red bar.
  • Pause and think any time you get a premature pass.

233 comments:

  1. I would never want to miss out any opportunity to read out your contents.
    morgand24

    ReplyDelete
  2. If you are being attentive to learn several strategies then you ought to browse this article, I am certain you'll get much additional from this article. payday loans online

    ReplyDelete
  3. I have spent a lot of the time in different blogs but this is really a unique blog for me.Healthy Relationship with Bare Factory

    ReplyDelete
  4. Here at this site really the fastidious material collection so that everybody can enjoy a lot. PPIClaimz.org

    ReplyDelete
  5. Great webpage buddy, I am going to notify this to all my friends and contacts as well. insurance rates for cars

    ReplyDelete
  6. I was looking for the blogs and sincerely I have got the good work here. alpha technologies

    ReplyDelete
  7. Awesome blog! Now In anticipation of a follow-up …. android phone

    ReplyDelete
  8. I’m inspired with the surpassing and preachy listing that you furnish in such little timing.
    Get more info about Experience Spaces

    ReplyDelete
  9. Nicest information!!! I'll be enchanted to greatly help due to what I've learnt from here. cheap car insurance

    ReplyDelete
  10. I’m glad to find so many useful and informative data on your website.
    Go to 01 Mei

    ReplyDelete
  11. It feels awesome to read such informative and unique articles on your websites.
    ppi reclaim

    ReplyDelete
  12. I don't cerebrate some of websites offer this typewrite of assemblage. Auot insurance quotes

    ReplyDelete
  13. I actually found this blog and that is amazing thing I enjoy reading this easy to understand stuff. Keep it up.
    visitor counter

    ReplyDelete
  14. Fascinating information I haven’t been experienced such information in quite a long time.good infographics

    ReplyDelete
  15. An unbelievable blog. This blog will indisputably be definitely recommended to my friends as well.
    infographics design

    ReplyDelete
  16. The Info in the blog is out of this world, I so want to read more. infographic

    ReplyDelete
  17. I definitely respect and am grateful for your point on every single object.social media infographics

    ReplyDelete
  18. This is really an excellent blog as well as its content.
    personal payday loans

    ReplyDelete
  19. I truly get pleasure from while I read your blogs and its content. infographics design

    ReplyDelete
  20. I was searching the blogs for a long time and that is good to know that I have found such blogs here. Great working! Keep it up!
    whole life insurance quotes

    ReplyDelete
  21. I have been dotty by reading your blog because it has a unique data. infographic

    ReplyDelete
  22. Finally I’ve found your blog, awesome way of explaining each and everything really.
    whole life insurance

    ReplyDelete
  23. Your writers have capability to make understand the users, great stuff you have provided to us.auto insurance

    ReplyDelete
  24. Thanks for this post; it’s really amazing to read.cheap auto insurance

    ReplyDelete
  25. I really enjoy reading and also appreciate your work. car insurance

    ReplyDelete
  26. I really enjoy reading and also appreciate your work. car insurance

    ReplyDelete
  27. Thanks dear for the articles…. Really helpful for me and it’s according to the purpose.
    Ivy League tutoring

    ReplyDelete
  28. You hit realize out of the most other topics.
    german tutoring

    ReplyDelete
  29. It's not my very first time to visit this blog; I’m visiting this daily and acquire superb info from here day by day.compare auto insurance rates

    ReplyDelete
  30. The complete blogs are really inconceivable and definitely everyone will share this information.
    How to clean solar panels

    ReplyDelete
  31. Fastidious blog you’ve got here. I’ve ever been seeing you just about many blogs recently.
    online cash loan

    ReplyDelete
  32. I suppose I've selected an unbelievable and interesting blog.ee customer service

    ReplyDelete
  33. I want to say thank to you people for this great and helpful info. Thanks!!!
    vodafone customer services number

    ReplyDelete
  34. Hi, just desired to let you know, I enjoyed this blog post. It had been funny. Carry on posting!
    online personal loans

    ReplyDelete
  35. Your blogs are easily accessible and quite enlightening so keep doing the amazing work guys.compare automobile insurance quotes

    ReplyDelete
  36. The stuff written in the blogs have allured me!!! visit us

    ReplyDelete
  37. congratulations guys, quality information you have given!!! single premium life insurance

    ReplyDelete
  38. I think I have never seen such blogs ever before that has complete things with all details which I want. So kindly update this ever for us.
    new homes

    ReplyDelete
  39. Your articles helped me more in all kind of topics.best weight loss foods

    ReplyDelete
  40. Your blogs and its stuff magnetize me to return again n again. North Carolina cash loans

    ReplyDelete
  41. The information in this blog is extremely useful for the people.
    pirater un compte facebook

    ReplyDelete
  42. Hi, just desired to let you know, I enjoyed this blog post. It had been funny. Carry on posting!
    Detox Drinks

    ReplyDelete
  43. The information in this blog is extremely useful for the people.
    comment pirater un compte facebook

    ReplyDelete
  44. Fascinating information I haven’t been experienced such information in quite a long time. ACLS Renewal

    ReplyDelete
  45. http://www.gardenbloggers.com/2012/02/garden-bloggers-on-cutting-edge-example.html?showComment=1391074563051#c6189155632113524159

    ReplyDelete
  46. You people have actually provided the best blogs that are easy to understand for the folks. pirater un compte facebook

    ReplyDelete
  47. You people have actually provided the best blogs that are easy to understand for the folks. pirater un compte facebook

    ReplyDelete
  48. Hey to everyone, it’s my first visit of the blog site; this blog includes awesome and actually best info for the visitors. lexingtonlaw

    ReplyDelete
  49. Hey buddies, such a marvelous blog you have made I’m surprised to read such informative stuff.chestnut brown hair color

    ReplyDelete
  50. Wonderful, just what a blog it is! This blog has provided the helpful data to us continue the good work.
    vietnam visa

    ReplyDelete
  51. I have seen so many sites but never saw this type of work that has won my heart!!
    mango exporter pakistan

    ReplyDelete
  52. I wanna thanks to a great extent for providing such informative and qualitative material therefore often.
    the best universal life policies

    ReplyDelete
  53. You people have actually provided the best blogs that are easy to understand for the folks. ansonia bridal

    ReplyDelete
  54. It’s my first time to visit this site & I’m really surprised to see such impressive stuff out there.
    shipping companies UK

    ReplyDelete
  55. I'm in no doubt coming back again to read these articles and blogs.bubblegum casting

    ReplyDelete
  56. This is an informative blog by which I have got that info which I really wanted to get.
    http://www.epicfollowers.com

    ReplyDelete
  57. The information you have given in the blog really marvelous and more interesting.
    buy twitter followers UK

    ReplyDelete
  58. Cool blog site friend I'm about to suggest this to all my listing contacts.
    Winzip

    ReplyDelete
  59. Really amazing blog, I’d love to discover some extra information. http://www.epicfollowers.com

    ReplyDelete
  60. Really amazing blog, I’d love to discover some extra information.buy twitter followers UK

    ReplyDelete
  61. An enormous round of applause, continue the great work.

    ny central booking

    ReplyDelete
  62. Pretty remarkable post. I simply came across your blog and desired to say that I have really enjoyed searching your blog posts.
    vietnam visa

    ReplyDelete
  63. This info you provided in the blog that was really unique I love it!!!swiss replica watches

    ReplyDelete
  64. These blogs are quite incredible that have provided the best knowledge. ny criminal lawy

    ReplyDelete
  65. I further than doubtfulness revalue your articles and blogs.

    free media player download

    ReplyDelete
  66. The individuals not reading your blogs stuff are missing out much qualitative contents. bubblegum casting reviews

    ReplyDelete
  67. I'm delighted to mature so additional functional and informative collection on your web site.
    sewing kit

    ReplyDelete
  68. Your contents are wonderful and recommended. SEO Services

    ReplyDelete
  69. Enthralling stuff I haven't been finished particular data in a lasting time.
    best credit repair services

    ReplyDelete
  70. I really enjoy reading and also appreciate your work.

    adt security

    ReplyDelete
  71. The Info in the blog is out of this world, I so want to read more.
    brisbane electrician

    ReplyDelete
  72. The blog and data in this, is very good and informative also.
    central booking staten island

    ReplyDelete
  73. Your blog is extremely brilliant especially the quality content is really appreciable.
    central booking bronx

    ReplyDelete
  74. The information you have given in the blog really marvelous and more interesting. criminal attorney ny

    ReplyDelete
  75. I endlessly am waiting on forthcoming to your posts again because I have impressed through your writing.
    Manhattan central booking

    ReplyDelete
  76. Continue the good work; keep posting more n more n more.
    replica watches

    ReplyDelete
  77. Regarding all aspects the blog was perfectly nice. Accident Claims

    ReplyDelete
  78. helpful siteThis is really pretty cool place I like it because it has everything I want more on this blog soon.

    ReplyDelete
  79. It’s my first time to visit this site & I’m really surprised to see such impressive stuff out there. click now

    ReplyDelete
  80. It’s my first time to visit this site & I’m really surprised to see such impressive stuff out there. click now

    ReplyDelete
  81. Waooow!!! Really very cool site of blogs. You can imagine what you have done for me.
    this form

    ReplyDelete
  82. Waooow!!! Really very cool site of blogs. You can imagine what you have done for me.
    this form

    ReplyDelete
  83. I’m glad to see that having got your blog site I have solved my whole issues regarding searching the stuff.
    click now

    ReplyDelete
  84. This is an informative blog by which I have got that info which I really wanted to get.website here

    ReplyDelete
  85. You people have actually provided the best blogs that are easy to understand for the folks.Learn About it

    ReplyDelete
  86. I think I have really come on the right place for getting the perfect info.
    for more info

    ReplyDelete
  87. You people have actually provided the best blogs that are easy to understand for the folks.
    Learn About it

    ReplyDelete
  88. The information in this blog is extremely useful for the people.
    green coffee bean extract

    ReplyDelete
  89. The information in this blog is extremely useful for the people.
    green coffee bean extract

    ReplyDelete
  90. You people have actually provided the best blogs that are easy to understand for the folks.
    click here

    ReplyDelete
  91. Really very informative content is here, thanks for sharing such info.
    Full Report

    ReplyDelete
  92. This blog is truly extraordinary in all aspects. ID Cards

    ReplyDelete
  93. This blog is truly extraordinary in all aspects. ID Cards

    ReplyDelete
  94. I think I have really come on the right place for getting the perfect info.
    credit repair

    ReplyDelete
  95. I have been really impressed by going through this awesome blog. who has lowest car insurance rates

    ReplyDelete
  96. I continuously continue coming to your website once more simply in case you have posted new contents.

    ReplyDelete
  97. I continuously continue coming to your website once more simply in case you have posted new contents.

    ReplyDelete
  98. You guys present there are performing an excellent job.
    home alarm system

    ReplyDelete
  99. congratulations guys, quality information you have given!!! lexington law reviews

    ReplyDelete
  100. congratulations guys, quality information you have given!!! lexington law reviews

    ReplyDelete
  101. I think I have really come on the right place for getting the perfect info.

    ReplyDelete
  102. payday lenders
    congratulations guys, quality information you have given!!!

    ReplyDelete
  103. congratulations guys, quality information you have given!!!
    payday lenders

    ReplyDelete
  104. exposed skin care reviews
    The information in this blog is extremely useful for the people.

    ReplyDelete
  105. I constantly emailed this site post page to all my friends, because if prefer to read it then my all friends will too.
    recipes for pasta salad

    ReplyDelete
  106. recipes for pasta salad
    I constantly emailed this site post page to all my friends, because if prefer to read it then my all friends will too.

    ReplyDelete
  107. This info you provided in the blog that was really unique I love it!!! ppi claims

    ReplyDelete
  108. This info you provided in the blog that was really unique I love it!!! ppi claims

    ReplyDelete
  109. I think I have really come on the right place for getting the perfect info.
    electric razor

    ReplyDelete
  110. You people have actually provided the best blogs that are easy to understand for the folks.

    rent car jakarta

    ReplyDelete
  111. Thank you so much you have given the great blogs site by which we can get more advantage.
    best philips electric shavers

    ReplyDelete
  112. Regarding all aspects the blog was perfectly nice. Best Electric Shaver 2014

    ReplyDelete
  113. Regarding all aspects the blog was perfectly nice. Best Electric Shaver 2014

    ReplyDelete
  114. how to lose man boobs fast
    I have visited lots of the blogs but this blog is truthfully wonderful.

    ReplyDelete
  115. I have visited lots of the blogs but this blog is truthfully wonderful.
    how to lose man boobs fast

    ReplyDelete
  116. Thanks meant for sharing this type of satisfying opinion, written piece is fastidious, that’s why I’ve read it completely. green coffee bean extract weight loss

    ReplyDelete
  117. If somebody wants expert take on the main topic of blogging next I advise him/her to go to this site, continue the fussy job. green coffee bean extract

    ReplyDelete
  118. I want to say thank to you people for this great and helpful info. Thanks!!!
    Kansas City SEO

    ReplyDelete
  119. Kansas City SEO
    I want to say thank to you people for this great and helpful info. Thanks!!!

    ReplyDelete
  120. Waooow!! Nice blog, this will be greatly helpful.
    linden method

    ReplyDelete
  121. Your articles are extremely fit and approved and incomparable.training course

    ReplyDelete
  122. That's a nice place of you; we have been polishing off there.phlebotomy certificate program

    ReplyDelete
  123. Height Increasing Shoes
    I think I have never seen such blogs ever before that has complete things with all details which I want. So kindly update this ever for us.

    ReplyDelete
  124. The information in this blog is extremely useful for the people.
    best Braun shaver review

    ReplyDelete
  125. I think I have really come on the right place for getting the perfect info.
    simple recipes

    ReplyDelete
  126. I think I have really come on the right place for getting the perfect info.nutrition

    ReplyDelete
  127. You people have actually provided the best blogs that are easy to understand for the folks.south beach diet

    ReplyDelete
  128. Your composing is purely awe-inspiring that I desired to read such high quality material...
    cervical cancer

    ReplyDelete
  129. Your blogs and its stuff magnetize me to return again n again. quick weight loss tips

    ReplyDelete
  130. creditrepair.com reviewsGreat blog you people have made here on this blog site, I will absolutely appreciate your work.

    ReplyDelete
  131. Great blog you people have made here on this blog site, I will absolutely appreciate your work.
    lexington law reviews

    ReplyDelete
  132. Those who are still far from your site they are missing the more brilliant stuff of the blogs.diet programs

    ReplyDelete
  133. Those who are still far from your site they are missing the more brilliant stuff of the blogs.diet programs

    ReplyDelete
  134. The info you provided in the blog that was really unique I love it!!!credit repair companies

    ReplyDelete
  135. I have been really impressed by going through this awesome blog.credit repair companies

    ReplyDelete
  136. The information in this blog is extremely useful for the people.protect america review

    ReplyDelete
  137. You guys present there are performing an excellent job. facebook marketing

    ReplyDelete
  138. I love all details that you give in your articles. increase facebook likes

    ReplyDelete
  139. Appreciate you guys you are doing a really terrific job.
    Puppy training

    ReplyDelete
  140. Puppy trainingAppreciate you guys you are doing a really terrific job.

    ReplyDelete
  141. buying car tipsWaooow!! Nice blog, this will be greatly helpful.

    ReplyDelete
  142. Waooow!! Nice blog, this will be greatly helpful.
    buying car tips

    ReplyDelete
  143. Waooow!! Nice blog, this will be greatly helpful.
    Maid Service Prices

    ReplyDelete
  144. Waooow!! Nice blog, this will be greatly helpful.
    Maid Service Prices

    ReplyDelete
  145. diet informationI constantly emailed this site post page to all my friends, because if prefer to read it then my all friends will too.

    ReplyDelete
  146. I constantly emailed this site post page to all my friends, because if prefer to read it then my all friends will too.
    diet information

    ReplyDelete
  147. Your contents provide me a lot of creative suggestions that I can seemingly utilize on my web page too.credit people reviews

    ReplyDelete
  148. Your contents provide me a lot of creative suggestions that I can seemingly utilize on my web page too.credit people reviews

    ReplyDelete
  149. Thanks for explaining what the possibilities might be.

    ReplyDelete
  150. Regarding all aspects the blog was perfectly nice. home security systems reviews

    ReplyDelete
  151. Regarding all aspects the blog was perfectly nice. home security systems reviews

    ReplyDelete
  152. Regarding all aspects the blog was perfectly nice. home security systems reviews

    ReplyDelete
  153. Regarding all aspects the blog was perfectly nice. home security systems reviews

    ReplyDelete
  154. It feels awe-inspiring to read such informative and distinctive articles on your websites.

    protect america review

    ReplyDelete
  155. I never ever read such type of info before this was really incredible. web url opener

    ReplyDelete
  156. You create sense out of the foremost complex topics.
    frontpoint review

    ReplyDelete
  157. Whatever you have provided for us in these posts really appreciative.
    home security companies

    ReplyDelete
  158. Bundles of thanks for providing such kind of blogs with the informative and impressive articles. get more likes on facebook - realfacebooklike.com

    ReplyDelete
  159. Quite informative and the interesting blog for everyone, I simply loved it. buy facebook likes and fans in cheap price! lifetime retention!

    ReplyDelete
  160. Your blogs and each of its stuff is so pleasurable and valuable it is making me come back soon.
    How to get rid of spots

    ReplyDelete
  161. How to get rid of spotsWaooow!! Nice blog, this will be greatly helpful.

    ReplyDelete
  162. This blog post is really great; the standard stuff of the post is genuinely amazing.Best Electric Shaver

    ReplyDelete
  163. This blog post is really great; the standard stuff of the post is genuinely amazing.Best Electric Shaver

    ReplyDelete
  164. It's been good to see your blog when I always look for such type of blogs. It’s great to discover the post here.
    royal dar al eiman Makkah

    ReplyDelete
  165. It's been good to see your blog when I always look for such type of blogs. It’s great to discover the post here.
    royal dar al eiman Makkah

    ReplyDelete
  166. Your blogs and its stuff magnetize me to return again n again. umrah package

    ReplyDelete
  167. This stuff is down t earth, hats off buds out there. linden method

    ReplyDelete
  168. Wasp dudes! Awesome stuff keep it up. linden method

    ReplyDelete
  169. Regarding all aspects the blog was perfectly nice. Electric Shaver

    ReplyDelete
  170. Regarding all aspects the blog was perfectly nice. Electric Shaver

    ReplyDelete
  171. after effects tutorialcongratulations guys, quality information you have given!!!

    ReplyDelete
  172. congratulations guys, quality information you have given!!!
    after effects tutorial

    ReplyDelete
  173. Your work article, blogs I mean over all contents is must read material. lifeinsurance

    ReplyDelete
  174. Your work article, blogs I mean over all contents is must read material. lifeinsurance

    ReplyDelete
  175. I'm in no doubt coming back again to read these articles and blogs. insurance cost by car make modelinsurance rate

    ReplyDelete
  176. I'm in no doubt coming back again to read these articles and blogs. insurance cost by car make modelinsurance rate

    ReplyDelete
  177. This info you provided in the blog that was really unique I love it!!! Best Electric Shaver

    ReplyDelete
  178. This info you provided in the blog that was really unique I love it!!! Best Electric Shaver

    ReplyDelete
  179. We are dealing in superior quality of methylone, our research center takes very step to produce the best quality methylone.for more detail visit our site

    http://methyloneshoppe.com/

    ReplyDelete