Click here to Skip to main content
15,881,812 members
Articles
Tip/Trick
(untagged)

Allways start with failing test!

Rate me:
Please Sign up or sign in to vote.
3.00/5 (1 vote)
13 Nov 2011CPOL 10.4K   1   2
Correct method for testing

Traditional TDD consists of three steps:



  1. Write a failing test
  2. Implement your code
  3. Write a passing test

Those steps are known as "red green" refactor.


In some cases, you need to add test to existing code, so you have the option to write a test which pass in their first run, my advice is don't go for it! I made this mistake, and therefore I am trying to warn you.


Why is writing a failing test a must?


It's not because of refactoring agenda which favors baby steps. It's because you may be writing a test which always passes! And the risk that you may feel comfortable with your code, when you're actually naked!


The chances of writing tests which always pass are going up when using non-trivial code inside the test, for example, using a mocking framework or using a dependency injection framework inside the tests.


It happened to me more than once, so don't take your chances: simulating a failing test is vital!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer GE
Israel Israel
I am Software Developer at GE company for more than 2 years,

I created LINQTutorial.net since I didn't found any other good dedicate LINQ tutorial

Comments and Discussions

 
GeneralReason for my vote of 3 the article gives good advice (write... Pin
moragos14-Nov-11 17:40
moragos14-Nov-11 17:40 
GeneralRe: Maragos thanks for your comment Pin
Delashmate14-Nov-11 20:47
Delashmate14-Nov-11 20:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.