Unit testing is a process of testing single unit of an application independently. Unit testing involves testing of smallest units of source code to determine they are working properly and are fit for the purpose.
Unit testing comes under white box testing and is done by developers. In unit testing test conditions are generated and executed by developers to check developed code meets its requirement and design.Unit testing is done before integration testing.
While testing developers pass a set of input values and checks for the expected result, if result is not as expected then this encourages developers to modify the source code without worrying much about how such changes might affect the functioning of other units or the program as a whole. Developers write tests for every class they produce.
The objective of Unit testing is to test not only the functionality of code, but also to ensure that the code is structurally sound and robust, and able to respond appropriately in all conditions.It is typically used to verify control flow and data flow, memory leak problems.
Who Does? (Role and Responsibilities):-
Developer Does unit testing.
White box technique is used for unit testing.
Types of Defects:- In unit test generally logical defects, control flow defects and coverage defects are found.
Test Basis:- For testing low level document (LLD) or code is used.
Entry:- In unit testing all code review defects are fixed.
- When all defects in unit testing are fixed (as per given criteria).
- When code coverage is achieved.
Tools:- Drivers, stubs, coverage and unit testing tools.
- Unit testing logs (UTI)
- Unit test report (UTR)
- Codes are more reusable. In order to perform unit testing piece of code is considered as single module so this code can be reused gracefully.
- In unit testing defects are detected at early stage so the cost of fixing the defects is also less ultimately reducing the cost of developing the software or application.
- In unit testing debugging is very easy, if a defect is caught or a test fails then only latest then only the latest changes need to be debugged. 4. Unit Tests provide a safety net of regression tests and validation tests so that you can integrate effectively.
- Unit testing can be time-consuming and tedious. Every time when a piece of code is written it needs to get tested and during initial round of testing there is a possibility of having many error so lot of time is wasted in debugging and fixing them.
- In case of unit testing lot of documentation needs to be maintained. Documentation like module number and its corresponding test record pass or fail.