1: The traditional coding method
2: test-driven development
It features the following
2.1: Write a failed unit test to prove that there is a flaw in the product code to fix the flaw
When we want to implement a user's Add method User.add, we will write a test method to verify the User.add. Of course the initial test will certainly fail, because we don't have
Write User.add encoding so that after the run fails we will implement this code until it is passed
2.2: Write code that meets the test expectations, which is tested by
2.3: Refactoring code
For the first time, our code is definitely designed to be readable, and the specification is not very efficient, so we will refactor our codes until we write good coding.
3: Advantages of Unit Testing: 3.
1: Quickly find bugs in your project
Because in the code of our own manual testing is not universal, analogy to verify null, not to add judgment, a lot of code is unrestrained, so in other people after testing everywhere is a bug, constantly repeated changes are not finished, began overtime overtime
Cause the morale of the people is low. And so on after the product on-line every day to deal with a variety of bugs very painful. So by adding unit tests early, this would reduce most of the hassle.
3.2: Code refactoring
Refactoring we are not unfamiliar, why refactor, because no refactoring is impossible to see, or naming rules, or methods too long, or inefficient and so on, but if we do not participate in unit testing, you such a refactoring, but also manually point to test
After the project is submitted, there are new bugs, and you might be working with people complaining, refactoring every day, and now there's a problem. The team will be complaining, the final result of everyone will not refactor the code, know that it is not right. So unit testing is very heavy in refactoring.
's Status
The advantage is personal opinion. Familiar with TDD can give advice
To be the art of reference Unit testing.
What is test-driven development