Types of software testing: The Unit Test
The purpose of the unit tests is to isolate each part of a program and show its correctness and completeness in the implementation, promptly bringing out any defects, so that they can be corrected easily before integration.
Unit testing is carried out using a white-box testing approach and typically consists of “test cases”, ie test cases, each of which should be independent of the others.
Given the strong link between source code, test cases and related specifications to be verified, the unit test is normally performed by the developer who was in charge of that particular portion of the program.
The test cases, in fact, are usually developed in parallel with the application code and are implemented through automatic procedures, able to re-run the test whenever there is a need.
The reason why this type of testing is fundamental and indispensable is that often the defects are more easily identifiable through the malfunctions that occurred in a smaller and more limited environment.
If the defects are identified and solved shortly after their introduction, the time for their localization and solution is considerably reduced.
The task of testing an entire application is considerably simplified, the correctness of each individual module has already been tested.
Another good reason for performing unit tests is that some defects only emerge in the presence of particular software configurations, which would be difficult to recreate in a more complex and vast environment.
In this regard, special “drivers” are introduced, which simulate the calling units of the tested component, and “stubs”, which simulate the called unit.
Moreover, the unit test lowers the costs, in terms of time and resources, for the identification and correction of defects, compared to those that would have had to face to obtain the same result through tests on the entire application.
In object-oriented programming, the typical component that constitutes the unit to be tested individually is the class, and the smallest unit test includes the constructor and the destructor.
In general, testing cannot identify all the errors in a program and the same is true for unit tests which, by analyzing the individual components by definition, cannot detect integration defects, performance-related problems and other system-related problems. general.
The unit test is therefore more effective if used in conjunction with other software testing techniques.