Is it bad practice to code the solution, then redo in TDD?

by maximedupre   Last Updated July 07, 2018 02:05 AM

I might be wrong, but I feel like the best approach to TDD is Solution, Red, Green, Refactor (adding "Solution" to the standard formula).

By coding the solution first, I feel like I am much more efficient when it comes to writing the actual tests. Sometimes, it's hard to know what the solution will be, much less what test to write. Writing a test when you have no idea where to start is daunting. I think you can also avoid pitfalls by rapidly coding a solution. Conversely, writing a test seems to be only a speculation that a problem will be solved once it passes. By coding first, you are assured that you will do the good verifications.

So my approach is:

  1. Code the solution
  2. Comment the solution and follow the standard formula (Green, Red, Refactor)

However, I might be missing something, maybe even an essential point of TDD. Maybe that by having thought through the problem a first time, you are less likely to make a complete set of tests, or the design will be different because of that.

Related Questions

Automating checks for "good" unit tests

Updated May 25, 2017 01:05 AM

How do you test backstop code?

Updated December 05, 2018 04:05 AM

How is code coverage measured?

Updated February 16, 2018 22:05 PM

Testable design in Swift

Updated June 22, 2015 23:02 PM