Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 31

Unit 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.

Unit Testing is of two types


• Manual
• Automated
Unit testing Under the automated approach
• A developer writes a section of code in the application just to test the function. They
would later comment out and finally remove the test code when the application is
deployed.
• A developer could also isolate the function to test it more rigorously. This is a more
thorough unit testing practice that involves copy and paste of code to its own testing
environment than its natural environment.
• A coder generally uses a UnitTest Framework to develop automated test cases. Using an
automation framework, the developer codes criteria into the test to verify the
correctness of the code. During execution of the test cases, the framework logs failing
test cases. Many frameworks will also automatically flag and report, in summary,
these failed test cases
The workflow of Unit Testing is
• 1) Create Test Cases
• 2) Review/Rework
• 3) Baseline
• 4) Execute Test Cases.
Unit Testing Techniques

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

• Bottom-up Integration Testing is a strategy in which the lower level


modules are tested first.
• These tested modules are then further used to facilitate the testing of
higher level modules.
• The process continues until all modules at top level are tested.
• Once the lower level modules are tested and integrated, then the
next level of modules are formed.
Bottom-up Integration Testing
• Advantages:
• Fault localization is easier.
• No time is wasted waiting for all modules to be developed unlike Big-
bang approach
• Disadvantages:
• Critical modules (at the top level of software architecture) which
control the flow of application are tested last and may be prone to
defects.
• An early prototype is not possible
Top Down Integration Testing

• Top Down Integration Testing is a method in which integration testing


takes place from top to bottom following the control flow of software
system.
• The higher level modules are tested first and then lower level
modules are tested and integrated in order to check the software
functionality.
• Stubs are used for testing if some modules are not ready
Top Down Integration Testing
• Advantages:
• Fault Localization is easier.
• Possibility to obtain an early prototype.
• Critical Modules are tested on priority; major design flaws could be
found and fixed first.
• Disadvantages:
• Needs many Stubs.
• Modules at a lower level are tested inadequately.
?How to do Integration Testing
The Integration test procedure irrespective of the Software testing
strategies (discussed above):
• Prepare the Integration Tests Plan
• Design the Test Scenarios, Cases, and Scripts.
• Executing the test Cases followed by reporting the defects.
• Tracking & re-testing the defects.
• Steps 3 and 4 are repeated until the completion of Integration is
successful.
Entry and Exit Criteria of Integration Testing

Entry and Exit Criteria to Integration testing phase in any software


development model
Entry Criteria:
• Unit Tested Components/Modules
• All High prioritized bugs fixed and closed
• All Modules to be code completed and integrated successfully.
• Integration tests Plan, test case, scenarios to be signed off and
documented.
• Required Test Environment to be set up for Integration testing
Exit Criteria:
• Successful Testing of Integrated Application.
• Executed Test Cases are documented
• All High prioritized bugs fixed and closed
• Technical documents to be submitted followed by release Notes
Best Practices/ Guidelines for Integration Testing
• First, determine the Integration Test Strategy that could be adopted
and later prepare the test cases and test data accordingly.
• Study the Architecture design of the Application and identify the
Critical Modules. These need to be tested on priority.
• Obtain the interface designs from the Architectural team and create
test cases to verify all of the interfaces in detail. Interface to
database/external hardware/software application must be tested in
detail.
• After the test cases, it’s the test data which plays the critical role.
• Always have the mock data prepared, prior to executing. Do not select
test data while executing the test cases.
System Testing
• System Testing is a level of testing that validates the complete and
fully integrated software product.
• The purpose of a system test is to evaluate the end-to-end system
specifications.
• Usually, the software is only one element of a larger computer-based
system. Ultimately, the software is interfaced with other
software/hardware systems.
• System Testing is defined as a series of different tests whose sole
purpose is to exercise the full computer-based system.
System Testing is Blackbox
Two Category of Software Testing
Black Box Testing •
White Box Testing •
System test falls under the black box testing category of software •
.testing
White box testing is the testing of the internal workings or code of a •
software application. In contrast, black box or System Testing is the
opposite. System test involves the external workings of the software
from the user’s perspective
?What do you verify in System Testing
System Testing involves testing the software code for following
• Testing the fully integrated applications including external peripherals
in order to check how components interact with one another and with
the system as a whole. This is also called End to End testing scenario.
• Verify thorough testing of every input in the application to check for
desired outputs.
• Testing of the user’s experience with the application.
• That is a very basic description of what is involved in system testing.
You need to build detailed test cases and test suites that test each
aspect of the application as seen from the outside without looking
at the actual source code
Software Testing Hierarchy
As with almost any software engineering process, software testing has a prescribed
order in which things should be done. The following is a list of software testing
categories arranged in chronological order. These are the steps taken to fully test new
software in preparation for marketing it:
• Unit testing performed on each module or block of code during development. Unit
Testing is normally done by the programmer who writes the code.
• Integration testing done before, during and after integration of a new module into
the main software package. This involves testing of each individual code module.
One piece of software can contain several modules which are often created by
several different programmers. It is crucial to test each module’s effect on the entire
program model.
• System testing done by a professional testing agent on the completed software
product before it is introduced to the market.
• Acceptance testing – beta testing of the product done by the actual end users.
Types of System Testing
There are more than 50 types of System Testing. For an exhaustive list of software
testing types click here. Below we have listed types of system testing a large software
development company would typically use
• Usability Testing – mainly focuses on the user’s ease to use the application, flexibility
in handling controls and ability of the system to meet its objectives
• Load Testing – is necessary to know that a software solution will perform under real-
life loads.
• Regression Testing – involves testing done to make sure none of the changes made
over the course of the development process have caused new bugs. It also makes
sure no old bugs appear from the addition of new software modules over time.
• Recovery Testing – is done to demonstrate a software solution is reliable, trustworthy
and can successfully recoup from possible crashes.
• Migration Testing – is done to ensure that the software can be moved from older
system infrastructures to current system infrastructures without any issues.
Types of System Testing
• Functional Testing – Functional Testing involves trying to think of any
possible missing functions. Testers might make a list of additional
functionalities that a product could have to improve it during
functional testing.
• Hardware/Software Testing – IBM refers to Hardware/Software
testing as “HW/SW Testing”. This is when the tester focuses his/her
attention on the interactions between the hardware and software
during system testing.
?What Types of System Testing Should Testers Use
• There are over 50 different types of system testing. The specific types used by a tester
depend on several variables. Those variables include:
• Who the tester works for – This is a major factor in determining the types of system testing
a tester will use. Methods used by large companies are different than that used by medium
and small companies.
• Time available for testing – Ultimately, all 50 testing types could be used. Time is often what
limits us to using only the types that are most relevant for the software project.
• Resources available to the tester – Of course some testers will not have the necessary
resources to conduct a testing type. For example, if you are a tester working for a large
software development firm, you are likely to have expensive automated testing software
not available to others.
• Software Tester’s Education- There is a certain learning curve for each type of software
testing available. To use some of the software involved, a tester has to learn how to use it.
• Testing Budget – Money becomes a factor not just for smaller companies and individual
software developers but large companies as well.

You might also like