What is Unit Testing?
Unit testing is the first level of testing performed on individual modules, components or piece of code. In unit testing the individual modules are tested as independent components to ensure that they work correctly and are fit to be assembled/integrated with other components. This testing is performed by developers. The developers usually write unit tests for the piece of code written by them.
As stated before, unit testing is the first level of testing. Once individual components are unit tested, integration testing is carried out.
Unit testing cannot be performed manually. The unit tests are always automated and more specifically use White-box testing technique as the knowledge of the piece of code and internal architecture is required to test the code. The developers create unit tests passing required inputs to the test script and asserting the actual output with the expected results.
Advantages of Unit Testing
- Defects within a module can be detected at earlier stages of development. Hence the cost of fixing the defects greatly reduces.
- Unit testing improves testing efficiency and better resource utilisation as testing of a module can be started without having to wait for other modules to finish.
- Exhaustive testing focusing on individual functionality is possible in unit testing.
- Unit tests aid in faster development and debugging as the impact of new changes can be easily detected by running the unit tests.
- Successful unit test report generates a sense of confidence about the quality of code. Modules successfully unit tested can be easily merged with other modules.
Limitations of Unit Testing
- Unit testing cannot detect integration or interfacing issues between two modules.
- It cannot catch complex errors in the system ranging multiple modules.
- It cannot test non-functional attributes like usability, scalability, overall performance of the system etc.
- Unit tests cannot guarantee functional correctness or conformance of application with its business requirements.