TDD is the abbreviation of Test Drive Development. In my view, that is a kind of develop procedure or develop concept. From the point of develop procedure, TDD can be divided into a circle:
Write a test
Make the complie pass
Run the test, see that it fails and check the error message is meaningful
Write enough code to make the test pass
Refactor
The circle aboved can be called code flow. In long term, that will help developer.
Goodness
Make sure code module is self-contained;
Test first make sure you have a clear goal
Badness
Tedious
Example
Hello World is a good start to understand TDD producre.
Write a failing test and see it fail so we know we have written a relevant test for our requirements and seen that it produces an easy to understand description of the failure
Writing the smallest amount of code to make it pass so we know we have working software
Then refactor, backed with the safety of our tests to ensure we have well-crafted code that is easy to work with
Enrich the test and go back to the first step;
More Complate Test
For Hello World , We want infer Some Name , not just “world”,like “Hello QingZhi”. So we chang the Test file, like this: