Use unit Test summary for the first time in a real project

Source: Internet
Author: User

I did a unit test before, but it hasn't been used in actual projects.

Because the previous project was written by me alone, the need for unit testing was really small, and the project itself was not difficult.

But this time it is not the same, the project itself is relatively large, and the division of labor is very clear.

I am responsible for the service layer and the data layer, which means that the code above interacts with the page to use my service.

That is to say, I did not take the page to test my own code situation.

At first I did not write unit test, and then the project every time someone said to use my service, I was particularly flustered, in case that one point wrong, it will lead to others time delay, so every time others use when I quickly look at what I wrote there is no problem, but this goes wrong, So I started writing unit tests.

After I finished all my services, I wrote all the unit tests in about 2-3 days, and although my unit tests were not specialized, I had at least the bottom of my mind when I called the service, and then there would be no low-level mistakes.

In that sentence, unit tests are not proof that you are right, but that you are not wrong.

To summarize, although unit testing is a bit of a waste of time, it does work.

1, it is best to write a service immediately after the unit test of the service, so that after the service can be very good to avoid making the same mistakes, this can save time.

2, the method of constructing objects in unit test, such as adding an object, the code of those new objects can be reused when actually writing the control layer, so it can increase the time.

3, unit testing in the actual page can also be used, because in practice, a lot of errors on the page actually look up very troublesome.

4, Unit Testing if the time is not urgent, be sure to test a variety of situations, there are paging must check to see if there is data on the second page, you can not just see the first page has data on it.

5, many times the error in the unit test is actually very clear, do not be afraid to read it.

6, the unit test must write good comments, especially for you to appear the problem of comments, many times we just finished testing, there are errors changed, and is not recorded in the comments. That's not right, unit tests have one more benefit, and when you're done with the project, when you review code, look at the comments on your unit tests and you'll immediately know what you've done wrong. When this project is summarized, you can gain more experience and reduce the chances of the next project making the same mistake.

Use unit Test summary for the first time in a real project

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.