Software Engineering Study Note one: unit testing

Source: Internet
Author: User

The completion of the software generally requires the cooperation of many people, as a member of the team, you can get a high quality and stable results by unit testing the modules that we are responsible for. Unit test, just met this concept is very confused, in the process of writing a program, generally in a number of compilations to find their own problems and correct them, once run through the no longer tube. Of course, the program and software are different concepts, some software needs to be maintained many times, in order to avoid the programmer to write some of the modules are misunderstood by other people to cause the software bug, after writing the code after the unit test is necessary.

The main steps for creating a unit test function are:

1. Setting up the data

2. Use the function of the type being tested

3. Compare actual results with expected results

And what is a good unit test? A series of criteria are listed below:

1. Unit testing should verify the correctness of the program on the most basic functions/parameters (e.g. classes in C + +)

2. Unit testing must be written by the author of the program

3. After the unit test, the machine status remains the same (delete the temporary file or directory created by the unit test during the teardown phase)

4. Unit tests are fast and produce repeatable, consistent results

5. Independence (when other modules are time-consuming or unstable, you can artificially construct the data for unit testing)

6. Unit tests should overwrite all code paths (public and private functions/methods must be tested)

7. For software that requires long-term use, it is best to automate unit testing

8. Unit tests must be saved and maintained with the product code

It seems that unit testing is not a simple matter, especially for programs with a lot of code, but if you do not write unit tests, you may encounter more difficult bugs later on.

Therefore, after writing a function of the software (such as the music software we want to do to read music function), it is best to do a test. and develop the habit of doing unit tests.

The citation is part of the law of construction, author Xin Zou.

Software Engineering Study Note one: unit testing

Related Article

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.