What is Unit Testing?
A unit may be an individual function, method, procedure, or a module
and is the smallest piece of code that can be logically isolated in
a system. Units are the smallest testable parts of an application
- Units are separately explored for identifying issues in Unit
Testing. Its primary purpose is to validate each unit
independently against its purpose or performance.
- Unit testing is done during the development process of an
application software by the software developers and
sometimes QA staff.
Advantages of Unit Testing
The main advantages are,
Unit testing helps software developers/software
testers in getting familiarized with the functionality provided
by a unit and on how to use the unit. It also helps them to
acquire a basic understanding of the unit API.
Unit testing allows the software developer to
manipulate the code to ensure the proper functioning of a
module. This improves code quality.
Unit testing enables testing parts of the project
without waiting for the completion of the whole project.
Defects are captured and rectified in the very
early phase of the project thus saving much testing time later.
Unit Testing Process:-
The unit testing steps can be briefed as follows.
Create test cases: - Identify a unit test
corresponding to the relevant feature to be tested. A section of
code is written by the software developer in the application to
facilitate this unit test. This section of code would later be
commented out and finally be removed when the application is
Reviewing test cases: - The section of code
tested is isolated to a separate testing environment. This helps
in exposing unwanted dependencies between the code being tested
and other units. These dependencies can then be removed.
Baselining test cases: - Software developers
use of Unit test frameworks or unit testing tools for handling
automated test cases.
Executing test cases: - During the execution
test cases corresponding to unit testing, the unit testing
framework helps to mark the test cases that fail and also helps
in reporting those failed test cases. The unit testing framework
further helps to stop the related testing in case of failures.
Unit Testing Methods:-
Unit testing can be performed in 2 ways.
Manual Testing: - The software tester
executes each step of a test case and does not require to know
about any testing automation tool. Manual Testing is tedious
especially for tests that are repetitive and have many
“100% of Automation is not always possible and so there is
always room left for some level of manual testing to be
Automated Testing: - The test cases to be
are automated and stored with the help of software testing
automation tools. The automation tool can record and save the
steps entered in test cases and they can be replayed as many
times as required.
“The automation tool can even compare the expected results
to the actual results and automatically generate the
Unit Testing Techniques:-
Software testers utilise three types of unit testing techniques while
testing each unit separately.
White Box Testing: - This testing requires
in-depth knowledge of the internal code structure of the program
to be tested in order to ensure if it’s performing its intended
function and to examine how it performs this.
“Unit testing is a type of white box testing where the
developer inspects the lines of code to be tested to point
bugs in the earlier phase of the development
Black Box Testing: - In this type of
software developers test the functionalities of an application
software without possessing any knowledge about its internal
code structure. The aim is to ensure that the functionalities
are carried out accurately and efficiently. These tests are
derived from the software specification document.
Grey Box Testing: - The grey box testing is
combination of black box and white box testing techniques. The
testers possess only limited knowledge about the internal code
structure of the application software to be tested. This type of
testing is designed to identify bugs that result due to improper
code structure or incorrect code.
Unit testing helps in ensuring the efficiency regarding the
performance of all the individual units of the application software
to be tested in its developmental phase itself. Detecting bugs and
rectifying them during unit testing saves time and money rather than
the testing done at the later stage of software development.
Automation of test cases corresponding to unit testing is a good
idea and can be done by software testing tools. A software testing
framework can be used to develop and maintain these test cases.