Basic methods for unit testing [Repost]

xiaoxiao2021-03-06  17

The basic method of the unit test [Repost] unit test object is the minimum unit - module of the software design. The basis of unit testing is to set up a description, and the unit test responds to all important control path design test cases in the module to discover errors within the module. Unit tests are multi-white box test technology, and multiple modules in the system can be tested in parallel. Unit test task unit test tasks include: 1 module interface test; 2 module local data structure test; 3 module boundary condition test; 4 modules All independent execution path tests; 5 modules Error handling path test. The module interface test is the basis for unit testing. Other tests are meaningful only if the data can flow correctly. The test interface should be correctly considered: 1 The number of actual parameters input to the form parameter is the same; 2 The actual parameter of the input is matched to the attribute of the formal parameter, and whether the actual parameter of the input is consistent with the dimension of the formal parameters 4 When calling other modules, whether the number of actual parameters is the same as the number of adjumbs of the modular module; 5 When calling other modules, whether the attribute gives the actual parameter is matched to the medial ginsenger of the modular module; 6 call other Whether the magnitude of the actual parameter is consistent with the formation of the modular module; 7 When calling the predefined function, whether the attribute and order is correct; 8 Is there any parameter reference to the current entry point; 9 Whether the read-only parameter is modified; 10 is the same as the definition of the entire variable, the module is consistent; 11 Whether certain constraints are passed as parameters. If the module includes external input output, the following factors should be considered: 1 File attribute is correct; 2 Open / close statement is correct; 3 Format Description Matching if the input output statement is matched; 4 buffer size is matched to the recording length; 5 files Whether it has been opened before use; 6 whether the file end is handled; 7 Have the input / output error; 8 There is a textual error in the output information; check the local data structure to ensure that the data is temporarily stored in the module in the program execution process It is complete and correct. The local data structure is often a wrong root, and the test case should be carefully designed. Strive to find the following types of errors: 1 Inappropriate or incompatible type of type description; 2 variables no initial value; 3 variable initialization or the provincial default; 4 Incorrect variable name (tuning or incorrectly truncated); 5 appears overflow, underflow and address exception. In addition to the local data structure, if possible, the unit should also find out the impact of global data (such as Fortran's public areas) on the module. Test each independent execution path in the module, the basic task of the unit test is to ensure that each statement in the module is at least once. At this point, the design test case is to find errors caused by incorrect comparison, incorrect comparison and inappropriate control flow. At this time, basic path testing and cyclic testing are the most common and effective test techniques. Common errors in the calculation include: 1 misunderstanding or use the wrong operator priority; 2 mixed type operation; 3 variable initial value; 4 precision is not enough; 5 expression symbols are wrong. The comparison judgment is often closely related to the control flow. The test case should also be committed to discovering the following error: Comparison between objects of different data types; 2 Errore using logical operators or priorities; 3 due to the limitations of computer representations, expectations Theoretically, the two quantities actually unhappy; 4 comparative operation or variable error; 5 cyclic termination conditions or impossible; 6 iterations When it is divergently, it cannot be exited; 7 incorrectly modify the cyclic variable.

A good design should be able to foresee a variety of error conditions, and preset various error handling paths. The error handling path also needs to be carefully tested. The test should focus on the following questions: 1 The error information of the output is difficult to understand; 2 record errors and actual The error does not match; Boundary condition testing is the final and most important task in unit testing. We know, software often invalidate on the boundary, using boundary value analysis technology, design test cases for boundary values ​​and left, right, and is likely to find new errors. The unit test process generally believes that the unit test should be completed immediately after the encoding, the source program is completed and the unit test can be started by review and compiling checks. The design of the test case should be combined with the review work. The test data is selected according to the design information, and the possibility of the above various types of errors will be increased. While determining the test case, the desired result should be given. A driver module (DRIVER) and (or), and several pile modules (STUB) should be developed for the test module, and the following figure shows the environment of the general unit test. The drive module is called "main program" in most cases, which receives test data and passes the data to the test module. After being called by the test module, "Main Program" prints "Enter-Exit" message. Drive modules and pile modules are software for testing, not part of software products, but it requires a certain development fee. If the drive and the pile module are relatively simple, the actual overhead is relatively low. Unfortunately, only a simple drive module and the pile module cannot complete some modules test tasks, which can only use the comprehensive test method discussed below. Improve the internal polymetidity of the module to simplify unit testing, if each module can only complete one, the number of test cases required will be significantly reduced, and the error in the module is more easily discovered.

转载请注明原文地址:https://www.9cbs.com/read-41021.html

New Post(0)