Ch5-2 Software Testing
Ch5-2 Software Testing
Unit Testing
• Unit Testing is a type of software testing where individual units or
components of a software are tested.
• The purpose is to validate that each unit of the software code
performs as expected.
• Unit Testing is done during the development (coding phase) of an
application by the developers.
• Unit Tests isolate a section of code and verify its correctness.
• A unit may be an individual function, method, procedure, module, or
object.
• Unit testing is first level of testing done before integration testing.
Unit testing is a WhiteBox testing technique that is usually performed
by the developer
?Why perform Unit Testing
• Here, are the key reasons to perform unit testing in software
engineering:-
• Unit tests help to fix bugs early in the development cycle and save
costs.
• It helps the developers to understand the testing code base and
enables them to make changes quickly
• Good unit tests serve as project documentation
• Unit tests help with code re-use. Migrate both your code and your
tests to your new project. Tweak the code until the tests run again.
How to execute Unit Testing
• In order to execute Unit Tests,
• developers write a section of code to test a specific function in software
application.
• Developers can also isolate this function to test more rigorously which reveals
unnecessary dependencies between function being tested and other units so the
dependencies can be eliminated.
• Developers generally useUnit Test framework to develop automated test cases for
unit testing.
The Unit Testing Techniques are mainly categorized into three parts:-
• Black box testing that involves testing of user interface along with
input and output.
• White box testing that involves testing the functional behaviour of the
software application.
• Gray box testing that is used to execute test suites, test methods, test
cases and performing risk analysis.
Unit Testing Tools
There are several automated unit test software available to assist with unit
testing. We will provide a few examples below:
• Junit: Junit is a free to use testing tool used for Java programming language. It
provides assertions to identify test method. This tool test data first and then
inserted in the piece of code.
• NUnit: NUnit is widely used unit-testing framework use for all .net languages. It
is an open source tool which allows writing scripts manually. It supports data-
driven tests which can run in parallel.
• EMMA: EMMA is an open-source toolkit for analyzing and reporting code
written in Java language. Emma support coverage types like method, line, basic
block. It is Java-based so it is without external library dependencies and can
access the source code.
• PHPUnit: PHPUnit is a unit testing tool for PHP programmer. It takes small
portions of code which is called units and test each of them separately. The tool
also allows developers to use pre-define assertion methods to assert that a
Unit Testing Advantage
• Developers looking to learn what functionality is provided by a unit
and how to use it can look at the unit tests to gain a basic
understanding of the unit API.
• Unit testing allows the programmer to refactor code at a later date,
and make sure the module still works correctly (i.e. Regression
testing). The procedure is to write test cases for all functions and
methods so that whenever a change causes a fault, it can be quickly
identified and fixed.
• Due to the modular nature of the unit testing, we can test parts of the
project without waiting for others to be completed.
Unit Testing Disadvantages
• Unit testing can’t be expected to catch every error in a program. It is
not possible to evaluate all execution paths even in the most trivial
programs
• Unit testing by its very nature focuses on a unit of code. Hence it can’t
catch integration errors or broad system level errors.
Unit Testing Best Practices
• Unit Test cases should be independent. In case of any enhancements
or change in requirements, unit test cases should not be affected.
• Test only one code at a time.
• Follow clear and consistent naming conventions for your unit tests
• In case of a change in code in any module, ensure there is a
corresponding unit Test Case for the module, and the module passes
the tests before changing the implementation
• Bugs identified during unit testing must be fixed before proceeding to
the next phase in SDLC
• Adopt a “test as your code” approach. The more code you write
without testing, the more paths you have to check for errors.
Integration Testing
• What is Integration Testing
• Integration Testing is defined as a type of testing where software
modules are integrated logically and tested as a group Integration
Testing is defined as a type of testing where software modules are
integrated logically and tested as a group
• A typical software project consists of multiple software modules,
coded by different programmers.
• The purpose of this level of testing is to expose defects in the
interaction between these software modules when they are integrate
• Integration Testing focuses on checking data communication amongst
these modules.
?Why do Integration Testing
Although each software module is unit tested, defects still exist for various
reasons like
• A Module, in general, is designed by an individual software developer whose
understanding and programming logic may differ from other programmers.
Integration Testing becomes necessary to verify the software modules work in
unity
• At the time of module development, there are wide chances of change in
requirements by the clients. These new requirements may not be unit tested
and hence system integration Testing becomes necessary.
• Interfaces of the software modules with the database could be erroneous
• External Hardware interfaces, if any, could be erroneous
Example of Integration Test Case
Sample Integration Test Cases for the following scenario:
Application has 3 modules say ‘Login Page’, ‘Mailbox’ and ‘Delete emails’ and each of them is
integrated logically.
• Here do not concentrate much on the Login Page testing as it’s already been done in Unit
Testing. But check how it’s linked to the Mail Box Page.
• Similarly Mail Box: Check its integration to the Delete Mails Module.
Test Case
Test Case Objective Test Case Description Expected Result
ID
Check the interface link between the Enter login credentials and click on the
1 To be directed to the Mail Box
Login and Mailbox module Login button
Check the interface link between the From Mailbox select the email and click a Selected email should appear
2
Mailbox and Delete Mails Module delete button in the Deleted/Trash folder
Types of Integration Testing
Software Engineering defines variety of strategies to execute
Integration testing, viz.
• Big Bang Approach :
• Incremental Approach: which is further divided into the following
• Top Down Approach
• Bottom Up Approach
• Sandwich Approach – Combination of Top Down and Bottom Up
Big Bang Testing
• Big Bang Testing is an Integration testing approach in which all the components or
modules are integrated together at once and then tested as a unit. This combined set
of components is considered as an entity while testing. If all of the components in the
unit are not completed, the integration process will not execute.
Advantages:
• Convenient for small systems
Disadvantages:
• Fault Localization is difficult.
• Given the sheer number of interfaces that need to be tested in this approach, some
interfaces link to be tested could be missed easily.
• Since the Integration testing can commence only after “all” the modules are designed,
the testing team will have less time for execution in the testing phase.
• Since all modules are tested at once, high-risk critical modules are not isolated and
tested on priority. Peripheral modules which deal with user interfaces are also not
isolated and tested on priority.
Incremental Testing
• In the Incremental Testing approach, testing is done by integrating
two or more modules that are logically related to each other and then
tested for proper functioning of the application. Then the other
related modules are integrated incrementally and the process
continues until all the logically related modules are integrated and
tested successfully.
Incremental Approach, in turn, is carried out by two different Methods:
• Bottom Up
• Top Down
Bottom-up Integration Testing