Search The Blog
About this site

@RoyOsherove

Subscribe!

This site aims to connect all the dots of my online activities - from tools, books blogs and twitter accounts, to upcoming conferences, engagements and user group talks.

from 5whys.com
Twitter: @RoyOsherove
My Book: The Art of Unit Testing
Latest Posts
« Moving to FeedBurner | Main | Microsoft's SharePoint treats FireFox as 2nd class citizen »
Sunday
Jul232006

How do you avoid bugs in your unit tests?

Oren tries to answer from difficult questions about TDD. One of them is related to how you'd make sure that your tests don't have bugs in them - which is a very important aspect of trust-worthy tests:

One of the best ways to make sure that you test is not buggy (a smoke test, if you will), is to to make sure it fails when it should.
That's why in TDD, you always start with a failing test.
You actually *run* the test and watch it fail before you make it pass.
This has two reasons:

  • To let you know that you have a bug.missing feature in your code, and to direct you to fix that target. now that the test passes, you can fix it , and then see the test fail.
  • If you can't make the test fail when it should, it probably has a bug so if the test fails to begin with, and then passes when you fix the *production* code, you're good. but if your test passes from the get-go, before you even fixed the production code, you know your test isn't good enough..

 

 

PrintView Printer Friendly Version

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>