Basic method for unit testing

zhaozj2021-02-08  381

Basic method for unit testing

(This article is reproduced from Software Engineering Expert Network

Www.21cmm.com)

The object of the unit test 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, and out of the module. 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.

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

New Post(0)