Unit test (unit tesTIng) refers to the inspection and verification of the smallest testable unit in the software. For the meaning of the unit in the unit test, in general, it is necessary to determine the specific meaning according to the actual situation, such as the unit in C language refers to a function, the unit in Java refers to a class, and the graphical software can refer to a window or a menu. Wait. In general, a unit is the smallest measured functional module that is artificially specified. Unit testing is the lowest level of testing activity to be performed during the software development process, and the individual units of the software are tested in isolation from the rest of the program.
In a traditional structured programming language, such as C, the unit to be tested is typically a function or sub-process. In an object-oriented language like C++, the basic unit to test is a class. For the Ada language, developers can choose whether to perform separate tests and functions, or unit tests at the Ada package level. The principles of unit testing are also extended to the development of fourth generation languages ​​(4GL), where the basic unit is typically divided into a menu or display interface.
Other development activities often associated with unit testing include Code review, StaTIc analysis, and Dynamic analysis. Static analysis is to study the source code of the software, find errors or collect some metric data, and do not need to compile and execute the code. Dynamic analysis provides information on execution tracking, time analysis, and test coverage by observing the actions of the software runtime.
Unit test implementation pointsModule interface
The interface of the module ensures that the data flow of the test module can flow and flow correctly. The following points should be checked during the test:
1) Whether the input parameters and formal parameters of the test module are consistent in number, attribute, and unit.
2) Whether the actual parameters given when calling other modules and the formal parameters of the called module are consistent in number, attribute, and unit.
3) Whether the parameters used to call the standard function are correct in terms of attributes, number, and order.
4) Whether the definition and usage of global variables in each module are consistent.
5) Enter whether only the formal parameters have been changed.
6) Whether the on/off statement is correct.
7) Whether the specified I/O format is consistent with the input and output statements.
8) Whether the file has been closed after the file has been opened or after the file is used.
2. Local data structure.
In unit testing, local data structure errors are more common errors, and the following factors should be considered in the test:
1) Is the description of the variable appropriate?
2) Whether a variable that has not been assigned or has not been initialized is used. 3) Whether the initial or default value of the variable is correct. 4) Is the variable name wrong (for example, misspelled).
3. Important execution path.
In unit testing, testing the path is the most basic task. Because exhaustive testing is not possible, test cases need to be carefully designed to find out if there are errors in calculations, comparisons, or control flows.
1) Computational errors: the arithmetic operations are not prioritized or misunderstood; the precision is not sufficient; the operation object
Type mismatch; algorithm error; symbolic representation of the expression is incorrect.
2) Compare and control flow errors: the amount that should be equal is not equal due to accuracy; the comparison logic is used for different types
The operator is incorrect or the priority is wrong; the loop is terminated incorrectly (such as multiple loops once or less), the infinite loop; the loop variable is improperly modified; when a branch loop is encountered, an exit error, etc.
4. Error handling.
A good design should be able to predict the conditions of the error and have a path to error handling. Although the computer can display the contents of the error message, the programmer still needs to handle the error to ensure the correctness of the logic for user maintenance.
5. Boundary conditions
The testing of boundary conditions is the final work of unit testing and is also very important work. It is easy to make mistakes at the border. When testing a block, you need to develop two modules:
6. Drive module
It is equivalent to a main program, receives the data of the test case, sends the data to the test, and outputs the test result.
7. Pile module
Also known as the stub module. The stub module is used to replace the submodule called in the test module, which performs a small amount of data processing in order to verify the population and output the information called and returned. Increasing the cohesion of the module simplifies unit testing. If each module performs only one function, the required test plan data will be significantly reduced for a piece, and it is easier to find and predict errors in the module.
Round Hole Pin Connector,Gold-Plated Round Hole Female Header,Dedicated Round Hole Pin Header,Single Row Round Hole Pin Connector
Shenzhen Jinyicheng Electronci Technology Co.,Ltd. , https://www.jycconnector.com