Unit Testing | Software Testing
Prerequisite – Types of Software Testing Unit Testing is a software testing technique by means of which individual units of software i.e. group of computer program modules, usage procedures, and operating procedures are tested to determine whether they are suitable for use or not. It is a testing method using which every independent module is tested to determine if there is an issue by the developer himself. It is correlated with the functional correctness of the independent modules. Unit Testing is defined as a type of software testing where individual components of a software are tested. Unit Testing of the software product is carried out during the development of an application. An individual component may be either an individual function or a procedure. Unit Testing is typically performed by the developer. In SDLC or V Model, Unit testing is the first level of testing done before integration testing. Unit testing is such a type of testing technique that is usually performed by developers. Although due to the reluctance of developers to test, quality assurance engineers also do unit testing.
Objective of Unit Testing:
The objective of Unit Testing is:
- To isolate a section of code.
- To verify the correctness of the code.
- To test every function and procedure.
- To fix bugs early in the development cycle and to save costs.
- To help the developers to understand the code base and enable them to make changes quickly.
- To help with code reuse.
Types of Unit Testing:
There are 2 types of Unit Testing: Manual, and Automated.
Workflow of Unit Testing: Unit Testing Techniques:
There are 3 types of Unit Testing Techniques. They are
- Black Box Testing: This testing technique is used in covering the unit tests for input, user interface, and output parts.
- White Box Testing: This technique is used in testing the functional behavior of the system by giving the input and checking the functionality output including the internal design structure and code of the modules.
- Gray Box Testing: This technique is used in executing the relevant test cases, test methods, test functions, and analyzing the code performance for the modules.
Unit Testing Tools:
Here are some commonly used Unit Testing tools:
Advantages of Unit Testing:
- Unit Testing allows developers to learn what functionality is provided by a unit and how to use it to gain a basic understanding of the unit API.
- Unit testing allows the programmer to refine code and make sure the module works properly.
- Unit testing enables testing parts of the project without waiting for others to be completed.
Disadvantages of Unit Testing:
- The process is time-consuming for writing the unit test cases.
- Unit Testing will not cover all the errors in the module because there is a chance of having errors in the modules while doing integration testing.
- Unit Testing is not efficient for checking the errors in the UI(User Interface) part of the module.
- It requires more time for maintenance when the source code is changed frequently.
- It cannot cover the non-functional testing parameters such as scalability, the performance of the system, etc.