Background
An efficient software development process for software developers is critical to determine the development of painful struggle, or continuous progress pleasure. Chinese blue-collar disdain of the software on the cumbersome lengthy intolerant of traditional development process, so that the majority of developers at a loss. The recent emergence of some of the software development process-related technologies to provide some of the more efficient and practical methods of software process development. Basis of comparison, one of the key technology is a Test Driven Development (Test-Driven Development). Although TDD everbright in Extreme Programming, but test-driven development can be a separate application. Following on from the developer point of view the use of introduction, allow developers to use the price as soon as possible, at least understand, master, application of this technology. The following sub-advantage theory, process, principles, testing technology, Tips and other aspects of this.
1. Advantages
TDD's basic idea is to pass the test to promote the conduct of the entire development. And test-driven development technology is not simply a test job.
Demand for the software development process has always been the worst in the sense of a clear description of volatile things. Say the demand here is not just referring to the user's needs, also includes the use of code requirements. A lot of developers fear most is that the latter would also like to modify a class or function of the interface changes or the expansion, why would such a thing happened is because the use of this part of code requirements is not well described. Test Driven Development is through the preparation of test cases, first consider the use of the code requirements (including functional, process, interface, etc.), and this goes for the description are defined, executable verification.
Through the preparation of this part of code, test cases, their functional decomposition, use the process of interface design have been conducted. And this point of view from the use of code design is usually more in line with the post-development needs. Can test the request of the code improve the cohesion and reuse are very helpful. Therefore the test-driven development is a kind of code design process.
Developers in the preparation of documents is usually very tired, but want to use and understand other people's code usually hope to have the guidance document. And test-driven development process of the test case source code is the best explanation.
Happiness is the foundation of the job has its own confidence in the results of the work of their own confidence. At present a lot of developers are often in fear: "code is correct?" "Hard to prepare the code did not have a serious bug?" "Changes to other parts of the new code has no effect?." This led to some even fear that the code should be amended to amend the point where they did not dare. Test-driven development on the test set can be used as a source of confidence in you.
Test Driven Development of course the most important feature is to guarantee the correctness of the code, be able to quickly detect, positioning bug. Quickly discovered that positioning bug are a lot of developers dream. Key code for the test set, as well as the continuous improvement of test cases for the rapid detection, positioning bug provided the conditions.
Some of my very complex code using TDD to develop complete, real-world applications found some bug, but will quickly be positioned to solve. After your application, it must be the kind of confidence for the development process, increasing functionality, perfect feeling, quickly found that the ability of positioning bug infection, enjoy this technology.
So what are the principles, methods provided above, which said these benefits? Here we take a look at the principles of TDD.
2. Principles of Test Driven Development The basic idea is to feature in the development of the code before the preparation of test code. That is to say clearly to the development of a feature, first of all consider how to test this feature, and completed the preparation of test code, and then the preparation of the relevant code to meet these test cases. Cycle then add other features, until the development of fully functional.
We are here to put this technology in areas ranging from coding to expand to the entire development process. Should be on the entire development process at all stages of test-driven, first of all consider how this stage of testing, verification, assessment, and preparation of test-related documents, and then start the next job, and finally re-authentication related work. The chart is a more popular test model: V test model.
At all stages of development, including needs analysis, outline design, detailed design, coding process should take the corresponding tests on the completed design of relevant test cases, test programs, test preparation plan. Stages of development mentioned here are examples of development activities in accordance with the actual adjustment. Related test documents are not necessarily in great detail the complexity of the document, or in what form, but should develop the habit of test-driven.
About the test model, have X test model. This test model, in my opinion, are the detailed stages of modeling and coding stages, it should be said a more detailed description of the detailed design and coding phase of the development of behavior. And the corresponding functions for a test-driven development.
【Figure X test model】
The basic principles should be said that very easy, then how to proceed with the actual operation which, following the development process in detail.
3. The process of software development at other stages of the Test Driven Development, Test Driven Development in accordance with the idea to complete the corresponding document can be tested. Below for the detailed design and coding stages of introduction.
Test Driven Development of the basic process is as follows:
1) clear to complete the current function. Can be recorded into a TODO list.
2) Express completed for this function in the preparation of test cases.
3) The test code does not pass the compiler.
4) the preparation of the corresponding function code.
5) the test.
6) Reconstruction of the code and to ensure the test.
7) complete cycle of all the features of the development.
Development process, usually put the test code and function code are kept separately here to provide a simple test framework for the use of examples, you can know to test the framework through its use. The following is a list of files.
project / project home directory
project / test to test the project home directory
project / test / testSeq.cpp test test seq_t documents, documents of other functional tests can be modified after the file copy
project / test / testSeq.h
project / test / Makefile test project Makefile
project / test / main.cpp test items of the main document, do not need to modify
project / main.cpp item master file
project / seq_t.h function code, test documents
project / Makefile project Makefile
Major basic flow, but to give you the code very easy to test, comprehensive testing without red tape, or there is a lot of testing principles and techniques need to be considered.
4. The principle of the test isolate. Different test code should be isolated from each other. Test on a piece of code only consider testing this code, not to consider the implementation details (such as its use of other types of boundary conditions).
A hat. Developers to do the process of developing a different job, such as: the preparation of the test code, the development of functional code, the code, such as remodeling. To do different things, to assume different roles. Developer to complete the corresponding work should remain focused on the current work, and not too many details to consider other aspects to ensure that only the heads of a hat. Avoid too many details to consider irrelevant, unnecessary increase in complexity.
Test list. Need to test the function of a lot of points. At any stage, should want to add the issue of functional requirements, the related function points added to test list, then continue to work on-hand. And keep the completion of the corresponding test cases, functional code, remodeling. First, to avoid omissions, but also to avoid interference with ongoing work.
Test Driven. The core of this comparison. Completion of a function, a certain category, first of all, the preparation of test code, to consider how they use, how to test. And in its design, coding.
Writing the first assertion. The preparation of test code, it should first of all, the preparation of functional code used to determine that statement, then the preparation of the corresponding auxiliary statement.
Testability. Function of the code design, development should be a strong testability. In fact, compared to follow good design principles of the code have a better test. Such as relatively high cohesion, as far as possible dependent on the interface.
Timely remodeling. Both the functional code or test code, the structure is irrational, duplicate code, etc., in the test passed, timely remodeling. About reconstruction, I will also detailed analysis of the author.
Small step forward. Software development is a very high complexity of the work of the development process to consider a lot of things, including the code correctness, scalability, performance and so on, because a lot of problems are caused by too much complexity. Extreme Programming has made a very good idea is to step forward. Put all of the scale, complexity, high job, broken down into smaller tasks to complete. For a category, a function of the completion of a functional, if too difficult to break down again. Leave the completion of each functional test code - function code - test - Reconstruction of the cycle. Through the decomposition of the whole system to reduce the complexity of development. This effect is very marked. Some small code after the completion of the function, the function of the code is almost not be able to debug through. A class method of implementation, it was soon to see the completion of the entire category you soon. Have been feeling a lot of features to be increased soon to see some you do not. You may even be shocked for this speed. (I understand that it was significantly reduced debug time errors generated by such a speed)
5. Testing Technology
5.1. Test range, particle size
What are the functions of the test? Will not be too cumbersome? When can I stop the test? These problems are more common. By Kent Benk Master, then to those who think you should test the code for testing. In other words, to trust their feelings, their own experiences. Those essential functions of the core code should be the focus of the test. Fatigue should be stopped to rest. Feel there is no need for a more detailed test, stop the current round of testing.
Test Driven Development does not emphasize the test should be able to afford, and should be to help alleviate the workload of our approach. As for when to stop the preparation of test cases, but also should be based on your experience, the functional complex, the core function of the code should prepare a more comprehensive, detailed test cases, otherwise the test can flow.
Static testing, there is no standard, but also should be able to change over time. Not enough to prepare for the start of testing the function of the code, with the emergence of bug, according to bug-related test cases can be filled.
Small step forward in principle, requires that we function on a large block tests, should be divided into smaller functional blocks for testing, such as the use of a class A category B, C, should be prepared to A using B, C function the test code before the completion of the B, C testing and development. Well, are not every small or small function which should be tested? In my opinion there is no need to. You should use your experience, the problem of those who may place the focus of the test, I feel the problem can not place it on the real problems, such as when the qualification testing it.
5.2. How to prepare test cases for the preparation of test cases on the use of the traditional testing technology.
Analog operation as far as possible the process of normal use.
Comprehensive test cases should be covered as far as possible branches of the core code path coverage as possible.
Test data as far as possible include the following: real data, boundary data.
Test statements and test data should be as simple as possible and easy to understand.
In order to avoid excessive dependence on other code, you can achieve simple piles or pile-type function (Mock Object).
If the internal status is complex or should determine the flow rather than status, you can log to verify the way the string.
6. Tips
Friend has a lot of questions, "How to test the correctness of the code protection? Are Writing Writing test code or test documents?" This is not to fall into "鸡生蛋, eggs, live chickens," the cycle. In fact, is no. Usually test code is usually very simple, usually around a particular situation to determine the correctness of some statement, if too complicated, you should continue to decompose. While the traditional development process usually emphasize test document. However, with the development pace of the ever-changing customer needs, maintain high-level (needs, outline design) documents can be tested, but also lower the cost of the test document is indeed too high. But also to verify the functional correctness of real-time test code is the best documentation of the code.
Software development process, except to comply with the above-mentioned test-driven development of some principles, a problem that required attention, to guard against over-design. The preparation of functional code should be concerned about the completion of the current function points, to pass the test, use the simplest and most direct approach to coding. Too many to consider the expansion of the latter, other features to add, has undoubtedly increased the excessive complexity of the problem easily. Should wait until you want to add these features when carrying out a detailed test-driven development. By that time, full set of test cases have to do basic, through continuous remodeling can easily add a relevant characteristic.







