(a) Unit Testing is a level of the software testing process where individual
units/components of a software/system are tested.
(b) The purpose is to validate that each unit of the software performs as designed
(c) A unit is the smallest testable part of software.
(d) It usually has one or a few inputs and usually a single output.
(e) In procedural programming a unit may be an individual program, function, procedure,
etc.
(f) In object-oriented programming, the smallest unit is a method, which may belong to a
base/super class, abstract class or derived/child class.
Advantages
(a) Unit testing increases confidence in changing/maintaining code.
(b) If good unit tests are written and if they are run every time any code is changed, the
likelihood of any defects due to the change being promptly caught is very high.
(c) If unit testing is not in place, the most one can do is hope for the best and wait till the
test results at higher levels of testing are out.
(d) If codes are already made less interdependent to make unit testing possible, the
unintended impact of changes to any code is less.
Codes are more reusable. In order to make unit testing possible, codes need to be
modular. This means that codes are easier to reuse.
(f) The cost of fixing a defect detected during unit testing is lesser in comparison to that
of defects detected at higher levels.
(g) Compare the cost (time, effort, destruction, humiliation) of a defect detected during
acceptance testing or say when the software is live.
(h) Debugging is easy. When a test fails, only the latest changes need to be debugged.
With testing at higher levels, changes made over the span of several days/weeks/months
need to be debugged.