High-performance Programmer's Practice notes: strengthening Code testing

Source: Internet
Author: User
Tags try catch

Preface: Code testing, is undoubtedly an important link in the programming process, how important to what extent? If the governance haze is programming, if you want to manage the fog haze, the most important thing is to reduce industrial pollution, and code testing is so, it can from the root of the bug to prevent the occurrence. The actual combat experience tells me that in the process of programming, when you successfully knocked the code over, then the time to follow the code of the naked eye scan, and through the SVN repository contrast, or with your recognized colleagues to code detection, when you write a small test case of important code, you will find that You have been able to fix a lot of bugs, if you follow the bug10 of the volume, the Code test can do 7 bug elimination.
Sharing with customersI once thought, far away from the customer, away from the user base, will let me a technology developer into the programming world of "Peach Blossom", there is no more noisy voice, there is no you hate the kind of "small white", more can let you away from those ignorant "needs."
However, as the author says, the user is the person with the code, and once we have finished writing the code, in many cases, we are like the code separated from a Wushan, and never meet again. And then the user, will be forced to work with your code all day, they have the most real experience of your code.
Due to the role of the job, I must be in the project of the trading platform in a number of jobs, from the analysis of customer needs to the product's on-line operation, I must be pro-force and for, natural and customers will often deal with, I found that I am responsible for the code, the customer is far more skilled than I, he can let the trading And I, only the envy of the share. And they are also the most important people to find software problems, at first, I think their feedback problem is "nonsense", but relatively speaking, if they can find the problem of software, why we can not do better, many times, and customers mingle, will allow us to better guarantee the quality of the software.
dyed VillainMost of the time, the software in the test environment, what problems are not, but once formally on-line, a variety of inexplicable problems will continue to emerge, we sometimes feel helpless, because these can not touch the minds of the problem let people start, for these problems, most of the time, we are not prepared enough.
So how can calmly handle this problem, the author said to create a dyed villain, for the program to add all kinds of trouble, so that we can get enough processing experience from the daily combat, in addition to improve our software processing capacity, a situation has a better way to handle.
Although at the present stage, we do not have to add a dyed villain appearance, but we have to ensure that the program is adequate, to try to get the program to deal with some edge situation (the probability is higher), so as to ensure that our program is no longer so fragile. In addition, before the on-line test, must not believe that your program what problems are not, sometimes, others will give you buried pits, you will be forced to jump the pit.
Code Reviewcode reviews between peers are the biggest contribution you can make to improving your code quality.
In a software maintenance organization, 55% of maintenance code changes were wrong before the code review was introduced, and the error rate dropped to 2% after the introduction of code reviews.
From the actual experience of the development, I am not difficult to find, there is a worthy of your trust of the reviewers, so you feel gratified and honored! After a person in charge of the test, he will help you to filter out you spend a lot of time can not find the problem, from the self-experience, code review is too important, I do not want to repeat this topic, remember to find a person you trust for the review.
Increased testing effortOriginally thought yesterday is docking Huaxia Bank test last day, nervous one weeks of nerves to a little relaxed a bit, however, in the liquidation of this morning, the original code there is a large loophole, on the access to the gold of the detailed check, in the treatment of the way obviously did not do "every opportunity", There are many pits buried. And yesterday night before the reflection of sleep, also let oneself find that the processing of frozen funds, should not accumulate daily.
All this is enough to prove that the test is not done in the imagination, even in all aspects of the brain can be thought of, we have handled good enough, however, in the face of reality testing, the program is still so fragile, need to be carefully carved, but also needIncreased testing effort, if we think that a problem after two or three test cases, there will be no error, obviously is not possible!
Unit Testacceptance of unit testing has become one of the biggest advancements in software development in the last 5-7 years.
Many of us are user junit, and this is a great way to help us test out the current class, the vulnerabilities in the current method, and the performance. So I would like to make a list of the "test-first" concepts that I think are very good, because the speed at which the transaction was set up before the server was optimized was by unit testing:
    • Reduce the cost of fixing bugs
    • It's more efficient than writing code directly.
    • Helps you to continually improve on the basis of not destroying existing functionality
    • can be used as sample code

unit Tests and beta testsonly when you give your code to a beta tester will the real value of the test really start.
Indeed, beta testing is the best simulation of real-world online scenarios, and beta testing has become standard for many software development. Our current futures trading system, after each revision of the code, will be updated to the corresponding test server for the relative real-world testing, to solve the problem as much as possible before the online, and this does help us too much.
Low -Fidelity usability testingIf you don't find a real user to do usability testing, you won't know if your program is working properly.
Needless to say, it is difficult for our small businesses and teams to find the right people to test the usability of the product, but we have to do it as much as we can. Many times, under the helpless, we do not have these groups, only reluctantly through their own self-test, we will be anxious to go online, and after the line, many times can not face the use of real environment pressure, the bug will eventually crush the product, we did lose a customer.
What's worse than a program crash?So far, I have found that Java's exception handling has been broken by most of us, the ubiquitous try catch can be seen dizzy, in order to ensure the "robustness" of the program, considering the user experience, we put the wrong layer of packaging, when encountered errors, We are very friendly to prompt users to wait patiently, which in many cases, so that users feel helpless.
See the author of this article, the heart is obsession, "rapid failure" is really very important, so that the user's data in the event of an error, can not be lost. We do not need to hide the mistake in the depths, of course, the Java transaction rollback, can help us do a lot, but try not to include in the try, try to let the error abort the next code continue to run,so that you can quickly locate the root cause of the problem, as soon as possible to solve the problem。

Practice notes for efficient programmers: strengthening code testing

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.