TDD advanced 1

Source: Internet
Author: User

During this time, I sorted out some knowledge about TDD:

TDD route

demand (unclear and incomplete)-design (unclear and incomplete)-test (clear demand and clear design)-implementation-reconstruction

not a test is written at the beginning, but a requirement is analyzed at the beginning, which is often unclear and incomplete. We need to make a general design for this requirement. Then begin to write test cases for a specific requirement. When writing test cases, you will find the hidden requirements. This is also the process of clarifying the requirements. In this way, developers can access the needs from the very beginning, instead of building a framework at the very beginning. Compile and implement Code for test cases, and then refactor the code as appropriate. Continue to write tests for the next requirement. In this way, you can not only closely grasp the requirements, ensure that your code is testability, but also leave a test project that monitors the code quality.

This is like creating an airplane.

follow our current software development method. First, we will analyze our aircraft indicators (Demand Analysis), draw aircraft sample Diagrams (System Design), and then develop or purchase components for the sample images, design the interface between components (architecture design ). Next, assign the modules to each engineer (module division). For example, I started to build the propeller (develop Dao and service). After the modules are created, we will test the modules (write test cases ), then we develop other components, such as the wing. Until the components of the entire aircraft are assembled (developed ). When you start a test flight, you have defined several test flight rules, such as takeoff, landing, and parallel (system acceptance ). Finally, you can deliver (complete development ).

what about formal aircraft manufacturing? We analyze our aircraft indicators (Demand Analysis), draw aircraft sample charts (System Design), and then develop and purchase the required components for the sample images, design the interface between components (architecture design ). Next, assign the module to

based on the comparison above, our development and aircraft creation are very similar, but there are also differences. Due to hardware, aircraft components must have detailed requirements before development, while software development can write test cases, refine requirements, and develop and implement them, this method is better than the hardware development mode, because it is a good way to improve self-confidence by using the compiler error check to drive us to implement code and remove errors at all times. If the test is completed, the implementation is also completed. While understanding the needs, analyzing the needs, and implementing the needs, we don't need to wait until all the needs are sorted out and then look back to achieve the needs much better, because the human memory is limited, and people do not want to do the same thing repeatedly. In fact, the most important thing is that after you implement a part of the code, you can explore more in-depth requirements and rebuild your code at all times to keep your code in the optimal state.

what should we do?

tests code that you think should be tested or that you do not have confidence in, including important functions and core code, testing should not be a burden, but should reduce the workload. If you feel that writing a test is a waste of time, you can write the implementation with confidence. If you regret it, You can also add the test code.

fine-grained testing, testability, high cohesion, and reuse of test code and code are required during writing and testing. Generally, you need to have a test list in your mind, write the test code, Use assertions to highlight the implementation requirements, and rely on interfaces, in addition, you can easily implement unit tests by using IOC and mock, instead of relying on too many components to delay testing.

use a test to Promote the Implementation, and refactor immediately after implementation.

the above step can be considered as a design during testing. Be sure to write test cases with design ideas. Otherwise, they will be separated from the architecture and tested for testing. As a result, the implementation code has no hierarchy or soul.

The benefits of the above steps are as follows:

The test case can be used to explain the process of implementing the requirement. The test code is equivalent to the document. After reading the test code, you can understand it without reading the document.

This gives developers confidence in every step of development and focuses on the current test.

Because each step is correct, and each step must ensure that the previous test can run, the entire code is guaranteed.

If a problem occurs, you do not need to perform integrated testing. unit testing can detect the problem.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.