Most unit tests are completed by developers. testers have a good technical background or may arrange unit tests when developing system software. Most unit tests are debugging by developers.ProgramOr the process of joint debugging of the Development Group system. The main purpose of this discussion is to expand the reader's horizons.
Unit testing generally includes five tests:
(1) Module Interface Test: Module Interface Test is the basis of unit test. Other tests make sense only when the data can be correctly imported into or exported from the module. The Module Interface Test is also the focus of the integration test. The test here is mainly to lay a good foundation for the future. The following factors should be taken into account when the test interface is correct:
Whether the number of input parameters is the same as that of formal parameters;
Whether the input parameters match the formal parameters;
Whether the dimensions of the input parameters are consistent with those of the formal parameters;
Whether the number of actual parameters provided when other modules are called is the same as that of the called module;
Whether the attribute of the actual parameter given when other modules are called matches the parameter attribute of the called module;
Whether the dimensions of the actual parameters provided when other modules are called are consistent with those of the called module;
Whether the number, attributes, and order of parameters used to call a predefined function are correct;
Whether parameter reference irrelevant to the current entry point exists;
Whether read-only parameters have been modified;
Whether the full-process variables are consistent in each module;
Whether to pass certain constraints as parameters.
If the module functions include external input and output, consider the following factors:
Whether the file attributes are correct;
Whether the open/close statement is correct;
The format description matches the input and output statements;
Whether the buffer size matches the record length;
Whether the file has been opened before use;
Whether the end of the file is processed;
Whether the input/output errors have been processed;
Whether there is a text error in the output information.
Test the local data structure;
Boundary Condition test;
All independent test paths in the module;
(2) Local Data Structure Test: Check the local data structure to ensure that the data temporarily stored in the module is complete and correct during program execution. Local functions are the basis for the entire function operation. The focus is on whether some functions are correctly executed and whether internal operations are correct. Local data structures are often the root cause of errors. You should carefully design test cases and try to find the following types of errors:
Description of unsuitable or incompatible types;
No initial value for the variable;
Variable initialization or missing values are incorrect;
Incorrect variable name (spelled incorrectly or incorrectly truncated );
Overflow, overflow, and address exceptions occur.
(3) boundary condition test: boundary condition test is the most important task in unit test. As we all know, software often fails on the boundary. Using the boundary value analysis technology, we design test cases for the boundary value and its left and right, and may find new errors. The boundary condition test is a basic test, which is also the focus of functional tests in subsequent system tests. It performs well and greatly improves program robustness.
(4) test all independent paths in the module: each independent execution path should be tested in the module. The basic task of the unit test is to ensure that each statement in the module is executed at least once. The purpose of the test is to find errors caused by incorrect calculation, incorrect comparison, and inappropriate control flow. The specific method is to debug the statements one by one. Common Errors include:
Misunderstanding or incorrect operator priority;
Hybrid Operation;
The initial value of the variable is incorrect;
Insufficient precision;
The expression symbol is incorrect.
Comparison and judgment are often closely related to the control flow. Pay attention to the following errors during testing:
Compare objects of different data types;
The logical operator or priority is incorrectly used;
Due to the limitations indicated by the computer, we expect the two numbers that are theoretically equal but not actually equal;
An error occurred while comparing operations or variables;
Cyclic termination conditions may not exist;
Iteration divergence cannot exit;
The loop variable is incorrectly modified.
Test each error handling path of the module: The program should not exit in case of exceptions. A good program should be able to anticipate various error conditions and preset various error handling paths. If the user does not follow the normal operation, the program will exit or stop the work, which is actually a defect. Therefore, the unit test should test various error handling paths. Generally, this test focuses on the following problems:
The output error information is hard to understand;
The recorded errors do not match the actual errors;
The system has been involved before the custom error handling segment of the program runs;
Improper exception handling;
The error statement does not provide sufficient error identification information.
Source: www.51testing.com