In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
1. Background
An efficient software development process is very important for software developers, which determines whether development is a painful struggle or the joy of continuous progress. People's disdain for blue-collar software and impatience with the tedious and tedious traditional development process make most developers at a loss as to what to do. Recently, some technologies related to software development process provide some more efficient and practical software process development methods. One of the most basic and key technologies is test-driven development (Test-Driven Development). Although the TDD light is greater than extreme programming, test-driven development can be applied alone. The following is introduced from the point of view of the use of developers, so that developers understand, master and apply this technology as soon as possible with the least cost.
2. Advantage 2.1 write test code first
The basic idea of test-driven development is to write test code before developing functional code.
2.2 consider the usage requirements of the code first
Test-driven development is to write test cases and first consider the requirements of the code (including functions, processes, interfaces, etc.), and this description is unambiguous and verifiable.
2.3 decomposition function
By writing the test case of this part of the code, the function decomposition, use process and interface are designed.
2.4 the test code is the documentation
When you want to use and understand other people's code, you usually want to have documentation for guidance, and the test case code generated in the process of test-driven development is the best explanation of the code.
2.5 correctness-> confidence
"is the code correct?"is there any serious bug in the hard-written code?"does the modified new code affect the rest of the code?" . The test suite provided by test-driven development can be used as a source of confidence.
2.6 Rapid location of bug
Of course, the most important function of test-driven development is to ensure the correctness of the code, which can quickly find and locate bug.
3. Principle
The basic idea of test-driven development is to write test code before developing functional code. In other words, after it is clear that you want to develop a function, first think about how to test the function, and complete the writing of the test code, and then write the relevant code to meet these test cases. Then cycle through and add other functions until all the features are developed.
3.1 V test model
3.2 X Test Model
4. Process
In other stages of software development, the corresponding test documents can be completed according to the idea of test-driven development.
1) identify the current functions to be completed. Can be recorded as a TODO list.
2) quickly complete the test case writing for this function.
3) the compilation of the test code failed.
4) write the corresponding function code.
5) pass the test.
6) ReFactor the code and ensure that the test passes.
7) complete the development of all functions in a loop.
5. Principle 5.1 Test isolation
Tests for different code should be isolated from each other. Testing a piece of code only considers the testing of that code, not its implementation details (for example, it uses the boundary conditions of other classes).
5.2 one hat
Developers have to do different work in the development process, such as writing test code, developing functional code, refactoring the code and so on. Do different things and play different roles. When completing the corresponding work, developers should keep their attention on the current work, without thinking too much about other details, and make sure that there is only one hat on the head. Avoid considering too many extraneous details and needlessly increase complexity.
5.3 Test list
There are many function points to test. You should add the relevant functional points to the test list at any stage when you want to add functional requirements issues, and then continue the work at hand. Then continue to complete the corresponding test cases, functional code, refactoring. First, to avoid omissions and to avoid interfering with the current work.
5.4 Test driver
This is the core. To complete a function, a class, first write test code, considering how to use it and how to test it. Then it is designed and coded.
5.5 write assertions first
When writing test code, you should first write assertion statements for functional code judgment, and then write corresponding auxiliary statements.
5.6 testability
Functional code design and development should have strong testability. In fact, the code that follows better design principles has better testability. For example, it is highly cohesive and depends on the interface as much as possible.
5.7 timely reconstruction
Whether it is the functional code or the test code, the unreasonable structure and repetitive code will be refactored in time after the test is passed. With regard to refactoring, I will write another article to analyze it in detail.
5.8 small steps forward
Software development is a very complex work, the development process to consider a lot of things, including the correctness of the code, scalability, performance and so on, many problems are caused by the complexity. Extreme programming puts forward a very good idea is to take small steps forward. Break down all the large-scale and complex work into small tasks to complete. For a class, the completion of a function will be decomposed if it is too difficult. The completion of each function goes through the cycle of testing code-functional code-testing-refactoring. Reduce the complexity of the whole system development through decomposition. This effect is very obvious. After a few small functional codes are completed, large functional codes can be passed almost without debugging. The implementation of each class method will soon see that the whole class is completed very quickly. Originally felt that a lot of features need to be added, will soon see a few. You may even be shocked by the speed.
6. Test Technology 6.1 Test scope, granularity
Test the code that you think should be tested. That is to say, trust your own feelings, your own experience. Those important functions, core code should focus on testing. If you feel tired, you should stop and have a rest. If you don't feel the need for more detailed testing, stop this round of testing.
Test-driven development emphasizes that testing should not be a burden, but a way to help us reduce our workload. As for when to stop writing test cases, you should also according to your experience, the code with complex functions and core functions should write more comprehensive and detailed test cases, otherwise the test process can be done.
There is no static standard for the test scope, and it should be able to change over time. For the functional code that did not write enough tests at the beginning, with the emergence of bug, you can make up the relevant test cases according to bug.
The principle of small step forward requires that when we test large functional blocks, we should first split them into smaller functional blocks for testing. for example, if a class A uses classes B and C, it should be written before A uses the test code of B and C functions. complete the testing and development of B and C.
6.2 how to write test cases
1) the operation process simulates the normal use process as far as possible.
2) the comprehensive test cases should be covered by branches as far as possible, and the core code should be covered by paths as far as possible.
3) Test data include real data and boundary data as far as possible.
4) Test statements and test data should be simple and easy to understand.
5) to avoid excessive dependence on other code, you can implement simple pile functions or pile classes (Mock Object).
6) if the internal state is very complex or the process should be judged rather than the state, it can be verified by recording a log string.
7. Tips
In addition to following the above-mentioned principles of test-driven development, one of the problems that need to be paid attention to in the process of software development is to beware of over-design. When writing functional code, you should focus on completing the current functional point and coding in the simplest and straightforward way through testing. Too much consideration of the later expansion, the addition of other functions, undoubtedly increased too much complexity, easy to cause problems. You should wait until you want to add these features before doing detailed test-driven development. At that time, with a complete set of test cases as the basis, it is easy to add relevant features through continuous refactoring.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 302
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.