I’ve heard this quite a bit when it comes to TDD, “You should always test before you code” actually I’ve never done full TDD or probably havent take advantage out of it, but how is it possible to test something that you havent even done???
Can you give me a clear example on how to do this??
Lately I’ve been thinking that this aspect of TDD is the same as the concept of programming by “wishful thinking” that I’ve read about in Structure and Interpretation of Computer Programs. For example, in lecture 2A of the MIT course taught by the authors, the following example is given for computing square roots as a function of fixed points:
This is shown before the
fixed-pointprocedure is defined. You don’t really need the definition to understand that you can use afixed-pointprocedure to compute square roots. Once you see how you’re going to use it, you can go about defining it.This is the same simple idea used in TDD. By writing tests for your methods before you write the methods themselves, you’re showing yourself how those methods are to be used.