I. What is TDD?
Simply put, before writing any functional code, write its test code. Procedure:
· Compile a test case as needed
· Write functional code to pass the test case
· Gradually add Test Cases
· Modify the function code so that the new test cases and the original ones both pass
· Refactoring, including functional code and Test Cases
Ii. Why TDD
Improve code quality. Thanks to the high quality and perfect test case set of function code, developers are more confident and can win the trust of others.
Improve the design. TDD ensures functional code testability, reduces coupling, improves component object models, and gradually improves the design during development.
Provides good documentation for functional code and maintains code and document synchronization. The agile Declaration advocates that the software that can run is better than all-around documents. A test case set is a document that is reliable and can run.
To some extent, it can replace program debugging. When each unit test focuses on each specific function, the problem is avoided earlier and better. In addition, debugging is manual and should not be repeated. The TDD test case set is automatically regression.
Effective Quality Control and project management. Managers can clearly understand the quality and development progress of projects through the results of unit tests on a daily basis.
Iii. TDD is a test and design.
When writing unit test code, it is actually under development. Before writing function code, design test cases from the perspective of function code users, and use the interface programming principles to reduce coupling and improve the design. It can be seen that TDD is also an object-oriented analysis, design, and development method. During the development of TDD, each class is tested separately, each part is designed and reconstructed frequently, and a complete set of testing cases is formed, TDD represents the process of continuous improvement and is an incremental design.
TDD (test driven development) is a testing technology and a design method. Its focus is not on test, but on development. It is an intent-driven software development method-intent programming.