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