The method of Node.js learning to summarize the mode code _node.js

Source: Internet
Author: User

Objective

Have you ever adjusted a piece of code, always feel the world ghosts?

Have you ever used an API when it always feels like it's an interface problem that calls a third party or is the documentation wrong?

Have you ever adjusted a bug when the source of the problem is the wrong way to use it?

Do you have a service that doesn't always feel like the document or the environment is compatible?

Believe in processes and methods, do not be misled by results ...

Overview

The mode code is similar to the case in many cases, but the results are different in importance, the police investigation for the people's stability, and our mode is for the stability of the system. In this way, we should not be guilty of any code and procedures, lest they be unreasonably punished.

Some of the following process methods are derived from the personal summary, from a personal point of view, some of the previous methods are accumulated through long-term experience, of course, the reference theory is relatively strong, and as a personal approach, it may be more suitable for the DS like me.

Test method

Code-Process Mode method

Code mode to pay attention to the first thing is the process, you have to understand the cause of the final result of the idea, that is, the process of committing a crime from the process of follow-up to get the result of the crime. In the analysis of the crime process, every doubt must be marked (that is, the log information mentioned in the code). After this analysis process, then the black box test, add input, verify the results. Finally, follow each step to verify your judgment and find out why.

The above scheme is a process-style mode. The advantages of this approach is self-evident, directly through a test can be analyzed clearly the entire process, but this way is time-consuming, clear their own code logic is fair, and want to understand the logic of others can be difficult to the sky.

Unit Test Mode method

The basic purpose of unit testing is to ensure the normal operation of a function, class, or function module, including the test verification of its exception. And as a programmer's favorite way to verify is "piling" (the meaning of piling is to provide false default data), this mode is very convenient, but there is a disadvantage is that can not be used again, because after we verify the normal, many developers will comment or delete it, So if we are in the development environment, but we want to test the environment validation, we have to write another piling logic, so see, to the current network, it will be more trouble. Since so much inconvenience, you can try the following procedure.

Add a unit test class, which needs to control its permissions, only through the background login or command line can be executed, the role of this kind of load is to the system's key logic to detect, and make the corresponding test output results. Believe that all interface classes can be tested by unit test classes. Many times programmers are questioning whether this is something we should do? Actually really need us to do, after all, many tests now do is black box test.

This mode is suitable for the development process, and can ensure that our current network code after the release of normal operation. I hope you will also be in the development phase when you plan your development time.

Fast Positioning method

The first two so complex processes are too idealistic? My code is only 100 lines, and the system is not complex. If this is the case, then the rapid positioning analysis. A lot of times you'll meet

1, input normal, output abnormal;

2, input normal, logic anomaly, output anomaly;

3. Abnormal input, normal logic and normal output;

4, input exception, logic anomaly, output none.

In the personal development process, I often encounter some of the above types of problems, such as in the Node.js development process, encountered string.length hint string no length method. At that time, I was wondering why the other string has a length method. Many students should know that the problem is that this string is not a string at all, just that you idealize it as String, which is the problem you entered. The best way to locate the problem is to print the input and print the output.

Perhaps other programs are not so simple, but the most basic is that in the main function will encounter the exception of the functions are input and output to determine, so you can quickly locate.

Remember: Don't take it out of context, self-righteous.

The above methods and procedures are only based on PHP or node.js, for C & C + + may exist similarities or differences. Don't like to spray, and look and cherish it.

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.