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.
The
primary goal of unit testing is to take the smallest piece of testable software
in the application, isolate it from the remainder of the code, and determine
whether it behaves exactly as you expect. Each unit is tested separately before
integrating them into modules to test the interfaces between modules. Unit
testing has proven its value in that a large percentage of defects are
identified during its use.
The most common approach to unit testing requires drivers and
stubs to be written. The driver simulates a calling unit and the stub simulates
a called unit. The investment of developer time in this activity sometimes
results in demoting unit testing to a lower level of priority and that is
almost always a mistake. Even though the drivers and stubs cost time and money,
unit testing provides some undeniable advantages. It allows for automation of
the testing process, reduces difficulties of discovering errors contained in
more complex pieces of the application, and test coverage is often enhanced
because attention is given to each unit.
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.
The
unit testing is done before the integration testing as shown in the image below
Unit testing helps in
maintaining and changing the code. This is possible by making the codes less
interdependent so that unit testing can be executed. Hence chances of impact of
changes to any other code gets reduced. Since the bugs are found early in unit
testing hence it also helps in reducing the cost of bug fixes. Just imagine the
cost of bug found during the later stages of development like during system
testing or during acceptance testing.

No comments:
Post a Comment