What is Unit Testing?

A unit is the smallest testable part of an application like functions, classes or procedures. Unit Testing is a Software Testing method by which individual units of source code, sets of one or more computer program modules are tested to determine whether they are fit for use. Unit tests are basically written and executed by software developers to make sure that code meets its design and requirements and behaves as expected.

The goal of unit testing is to segregate each part of the program and test that the individual parts are working correctly. This means that for any function or procedure when a set of inputs are given then it should return the proper values. It should handle the failures during the course of execution when any invalid input is given. Unit Testing is performed by using the White Box Testing method.  It is the first level of testing and is performed prior to Integration Testing.

Advantages

  • Unit testing helps in changing and maintaining code. If good unit tests are written and are run every time any code is changed, it is possible to catch any defects introduced due to the change. Also, if codes are made less interdependent to make unit testing possible, chances of impact of changes to any other code gets reduced.
  • Codes are more reusable. In order to make unit testing possible, codes need to be modular. This means that codes are easier to reuse.
  • Writing tests takes time but the time is compensated by the less amount taken to run the tests. The effort required to find and fix defects found during unit testing is very less in comparison to the effort required to fix defects found during system testing or acceptance testing.
  • Since the bugs are found early in unit testing hence it also helps in reducing the cost of bug fixing.
  • Debugging is easy. When a test fails, only the latest changes need to be debugged.
  • Simplifies integration Unit testing may reduce uncertainty in the units themselves. By testing the parts of a program first and then testing the sum of its parts, integration testing becomes much easier
Functional Testing
Functional Testing
Previous Article
Smoke Testing
Smoke Testing
Next Article
Lakshay Sharma
I’M LAKSHAY SHARMA AND I’M A FULL-STACK TEST AUTOMATION ENGINEER. Have passed 16 years playing with automation in mammoth projects like O2 (UK), Sprint (US), TD Bank (CA), Canadian Tire (CA), NHS (UK) & ASOS(UK). Currently, I am working with RABO Bank as a Chapter Lead QA. I am passionate about designing Automation Frameworks that follow OOPS concepts and Design patterns.
Reviewers
Virender Singh's Photo
Virender Singh

Similar Articles

Feedback