I appreciate TDD and think it indispensable but always write my tests ONLY after I write my source code then refactor accordingly. I can never bring myself to write the test first then the source to pass the test. So I always reverse the process. Is this a bad practice on my part? What are the disadvantages of doing it in reverse like me?
If you don't write your tests first then it's arguably not TDD. With TDD you normally write the test, watch it fail, then implement to make it pass.
The advantages over your workflow are:
You can mitigate the risks of all of those points, so it's down to you whether you want to keep going the way you are or switch to test first.
If you write the tests afterwards, do they really drive the development/design? I wouldn't think so.
To expand on Steven Robbins' answer: If your test does not fail before you make it pass, how do you know it is testing the right thing?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With