Test Driven Development By Example outlines a few strategies for getting your tests to green.

  1. Fake It
    1. This is the quickest way to get it green.  Simply supply a constant value at first to get it passing.  Once it turns green, replace it with  a variable and continue until you have the real code that is needed there.
  2. Use Obvious Implementation
    1. If you are confident and you know the correct implementation, simply write it.  The test will validate that you are right.
  3. Triangulation
    1. Write two or more examples that generalize code.  This is the most conservative approach.

These strategies can be used interchangeably when doing TDD.  If you put it on a scale of when to use which strategy, Obvious Implementation is on the far left, being the most free and not needing to check with dummy values.  The far gaspedalright is Triangulation.  It requires multiple examples to validate the code.   This does create some duplication, but enables you to make small steps in the code.

When coding, you can use these strategies like a gas pedal.  If you know the implementation, step on the pedal and use Obvious Implementation.  But if you hit a red light, time to switch gears and maybe go to Fake It or Triangulation to get back green.