With TDD, you don't really like the design. The idea is that you must first find out what you need before starting with a useful design. Tests ensure that you can easily and reliably change your application when the time comes that you need to decide on your design.
Without TDD, this happens: you create a design (which is probably too complex in some areas, plus you forgot to accept some important facts because you did not know about them). Then you start to implement the design. Over time, you will realize all the flaws of your design, so you change it. But a design change does not change your program. Now you are trying to change your code in accordance with the new design. Since the code was not written to be easy to change, it will ultimately fail, leaving you with two projects (one broken and the other in an unknown state) and a code that also doesn't work.
To get started with TDD, include your requirements in the test. To do this, ask: "How do I know if this requirement is met?" When you can answer this question, write a test that will answer this question. This gives you an API that your code must adhere to. This is a very simple design, but one that a) always works, and b) that is flexible (because you cannot check inflexible code).
Also, starting with the test, you will turn into your own client. As you try to make the test as simple as possible, you will create a simple API that will do the test work.
And over time, you will learn enough about your problem area to be able to make a real design. Since you have many tests, you can change your code to fit your design. Without a final violation of anything along the way.
What is the theory :-) In practice, you will encounter several problems, but this works very well. Rather, it works better than anything else I came across.
Aaron digulla
source share