Three Methods of Moving Forward in TDD
So, you have written your first test, and it is failing for the right reason. Now what? How do you make it pass (make it green)? There are a few simple ways to achieve this.
From Red to Green
- Fake it
Just return the exact value you need. If your test expects a zero from a method, simply do it. Usually, you use this when you are unsure about how to implement a specific functionality, or your previous steps were too significant, and you cannot figure out what went wrong. Something that works is better than something that doesn't work!
- Obvious implementation
When you are sure of the code you need to write, write it, and see the test go green! Most of the time, you will use this method to move forward with TDD quickly.
- Triangulation
When you want to introduce new behavior, write a new and more specific test that forces the code to be more generic (triangulation equals using tests as pivot points...