Test-driven development and eXtreme Programming

Source: Internet
Author: User
Tags xunit

With the development of the global economy and the popularization of computer technology, the demand for computer software in various industries is increasing. At the same time, the quality requirements for software are getting higher and higher. In stark contrast, with the increase in software requirements and scale, it is difficult to deliver software to users in a timely manner and to satisfy users. Traditional software engineering methods have been challenged, and many improved software development methods have emerged. Extreme Programming (Extreme Programming, XP) Is a new agile development method applicable to small and medium systems in such an environment. In extreme programming, the most distinctive principle is to adopt a test-driven development model. Test-driven development is the embodiment of software development practices in extreme programming methods.CodeQuality plays a crucial role. At the same time, it is becoming a new trend of thought in the industry.

I. Overview

The process of software development in the industry has been dominated by traditional software engineering methods. The traditional software engineering method follows the waterfall model or its variants from the problem definition, feasibility analysis, and requirement definition of the system. The above steps must be completed at the beginning of each step, for example, the requirement analysis of the system requires that the system be completely analyzed before entering the next stage. If one of the steps is not completed, or if the steps are completed but there are problems, it will have immeasurable impact on the future development process. As the industry is paying more and more attention to software quality, some new software development ideas have sprung up. Extreme Programming is one of the most influential new ideas.

Extreme Programming is1998BySmalltalkMasters in the communityKent BeckFirst, a new software development method is proposed. It is a thorough and rigorous software development process. It is based on the principles of simplicity, communication, feedback, and courage, and fully considers the human factors to achieve the highest customer satisfaction. This method is suitable for the development of small and medium-sized systems. This lightweight software development method puts forward extremely high requirements on software quality. To ensure the quality of the developed software, this method proposes the idea of test-driven development (TDD.

Test-driven development is different from the previous development process of code first and then testing,Kent BeckThe proposed development method is the opposite. Do not rush to write a new featureProgramCode, but write a test case for the code to be written in the future. In this case, the automated test tool is used to execute the test case. Of course, the result is not passed. To make the test case run correctly, we need to write and modify the code until the Code meets the requirements of the test case, and the test case can run correctly, this indicates that the newly added function has passed the unit test. At least at the unit code level, there is no problem. Test-driven development is recommended for automated testing tools.XunitTools.Kent BeckAndErich GammaOpen-source tools jointly developedJUnitYesJavaThe Gospel of testing-driven development by developers. Under the guidance of the test-driven development idea, this testing framework can greatly improve development efficiency, enhance software quality, and minimize development costs.

In short, the test-driven development method is a development method that tests first and codes later. It seems that it is only a step adjustment, but its effect is far-reaching. As a basic strategy for extreme programming solutions, test-driven development has a deep impact on each principle and strategy of extreme programming.

It fundamentally changes the development process of developers in the software development process. Once it changes the testing phase after coding, developers will test their own code.

Ii. Relationship between test-driven development and eXtreme Programming

As a new software process methodology, extreme programming emphasizes the process of human-to-human collaboration. Therefore, successful software development should take full advantage of human advantages, however, the weakness of people is weakened, which highlights the role of people in the software development process. At the same time, it is a highly dynamic process. It uses a very short iteration cycle to respond to changes in requirements. Under the four basic activities of coding, testing, listening, and feedback, in practice, the core value of extreme programming is realized:

1. Relationship between test-driven development and Core Value of Extreme Programming

Extreme Programming has its core values: communication, simplicity, feedback, and courage. As the basic development principle in extreme programming, test-driven development fully embodies the value of this new development idea.

(1) There is no doubt about the role of communication in the software development process. Communication can minimize misunderstandings caused by poor communication between developers, customers, and management personnel. Many of the practices of extreme programming are implemented by communication, which cannot be carried out without communication, such as unit testing, Pair programming, and work evaluation. Test-driven development is inseparable from these methods. Only testing-driven development for methods such as Pair Programming makes sense. In this case, a large amount of communication is also required, which shows the importance of communication principles.

(2) The value of simplicity is a very important embodiment in the idea of extreme programming. The whole process of extreme programming is represented by the simple word, simple design and simple code, as long as you can perform simple operations, it will not be complicated. As long as it meets the current requirements and can work, a simple solution is the best solution. Instead of implementing a complex system, it is better to design a simple system that can meet the current needs, because you will never consider what the next requirement is. This is exactly the case for test-driven development. The compilation of test cases follows the simple principle and meets the design requirements. The simpler the better. You only need to pay attention to the current needs and do not consider future changes. The current design can meet the current needs. Obviously, the current tests only need to meet the current needs. Test Cases are written based on the design.,It can be said that,Writing Test cases is also part of the design.,Simple principles also play a guiding role. Therefore, code writing is based on this principle,AlgorithmThe simpler the implementation, the better. You just need to pass the test.

(3) feedback is a valuable resource. In extreme programming, feedback is very important in design, testing, and development. For example, developers can obtain user feedback as soon as possible during the design, and the more detailed the better, so that they can ensure that their results meet the needs of users. The same is true for testing. Test-Driven Development implements this value. First, write the test case, use the feedback of the error information that has not passed the test, learn the reason why the code has not passed the test case, and learn the error location based on the information, then, based on the problems that have occurred, modify the code step by step so that the Code gradually meets the requirements of the test case. After running the test case several times, the code is finally fed back to the successful information that passes.

(4) courage is the most important core value. BecauseXPEmphasize"Embrace change"Therefore, you must be brave enough to modify your code and discard the bad code. This value reflects the mentality of developers. Test-driven development further encourages developers and provides a good mechanism for convenience in practice. The process of writing a test before writing code is exactly the embodiment of this mechanism. You must be brave enough to face the error feedback from test cases. For exampleXunitIn the use of the testing frameworkRed BarThe error message is not terrible, which is the significance of test-driven development. Write and modify the code based on the error information, face it with courage, and finally solve the problem successfully passed the test, showing the expectedGreen Bar. Courage can further enhance confidence, improve efficiency, and make the whole process develop in a virtuous circle.

2. Relationship between test-driven development and design in eXtreme Programming

The design concept proposed in extreme programming is very different from that of traditional software engineering. It abandons the principle of nearly demanding design in traditional methods and weakens the comprehensive and meticulous design. In extreme programming, do not require a very detailed design of the requirements, but follow the simple principle to make a simple design of the existing requirements. You do not need to consider it later, because you never know what needs will be added in the future.Martin FowlerThe so-called design is to allow you to easily modify the software for a long time.

Extreme Programming seems to simplify the design and weaken the basis for development. But in fact, its idea is to further clarify that the current problems should be paid more attention to during software development, and fully consider the current needs to meet the current needs of the customer, instead of time-consuming and labor-consuming for future needs, only in this way can we make the software meet the customer's needs. Test-driven development has great advantages in implementation design. One of the features of test-driven development is to write the test before writing the code. At this time, the significance of writing test cases is extraordinary. On the one hand, test cases have a common role in testing code. After the code is compiled, developers can determine its correctness. On the other hand, in extreme programming, design is a continuous process, To a certain extent, test cases are also a manifestation of the requirement document. Writing Test cases is actually a process of analyzing and designing requirements. This is a unique aspect of extreme programming and test-driven development. The writing of test cases is actually to judge the input and output of units. The design of the input and output is to analyze the system requirements, instead, it is best to use real system data for setup. After the test case is compiled, the Code starts to be written. All the purpose here is to pass the test, but the meaning is to fully meet the requirements of the system. Writing a test is no longer a pain for developers, but a design process to understand system requirements. This change can be said to have a great positive impact on software development, this is also the essence of test-driven development.

Design is integrated into development, and design is improved in development. the complementary relationship between the two is fully and thoroughly embodied in extreme programming. That is why the new idea of test-driven development was quickly promoted.

3. Relationship between test-driven development and eXtreme Programming

The idea of extreme programming is people-oriented, which is different fromCMMAnd other heavyweight development methods, it is completely from the engineering perspective of system development, in which people completely become loyal executors under the box. Extreme Programming has more considerations in terms of human nature, such as Pair programming during 40 hours of work every week. Test-driven development also embodies this principle.

Human activities have a high degree of purpose, and establishing appropriate goals has an important psychological effect. For example, this is especially true during testing. If our main purpose is to prove that there are no errors in the program, the subconscious will do it unconsciously in this direction, so in the process of writing the test, we will choose some test data that best prevents program errors. However, if our goal is to prove errors in the program, then some test data that is easy to find and contains errors will be selected. The latter attitude will add more value to the program than the former. The definition of traditional testing means that the process of program testing is destructive, and its degree is even unacceptable.

Test-Driven Development: From the Perspective of human nature, test first and code later. Instead of performing destructive testing after the traditional encoding is complete. In this way, our encoding has a very clear purpose. The purpose of each code is to pass the test. From previous destructive methods to a constructive method. There are clear goals for how to meet these tests. developers can solve immediate problems with a normal mentality and write high-quality code to pass these tests. Under the influence of this positive attitude, the efficiency of developers will be greatly improved. At the same time, this constructive method also plays an important role in the development of the entire team.

4 , Summary

As a basic development strategy of extreme programming, test-driven development fully reflects the core value of extreme programming. This new development idea is combined with the simple design, Pair programming, refactoring and other principles of extreme programming to form a series of practical kernels. Other Principles are based on it. The software quality has been greatly improved on the premise of highlighting the characteristics of human nature. With the development of test-driven development and the promotion of extreme programming ideas, more and more software enterprises begin to use this method directly or indirectly. I believe that in the near future, enterprises adopting this method will obtain high-quality software products from them, and their customer satisfaction will be greatly enhanced.

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.