A unit is the smallest testable part of an application like functions, classes, procedures, interfaces. Unit testing is a method by which individual units of source code are tested to determine if 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 gracefully during the course of execution when any invalid input is given.
A unit test provides a written contract that the piece of code must assure. Hence it has several benefits.
Unit testing is basically done before integration as shown in the image below.
Definition by ISTQB
Unit Testing is performed by using the White Box Testing method.
Unit testing should be done before Integration testing.
Unit testing should be done by the developers.
Advantages of Unit testing: