Professional Documents
Culture Documents
15 Module 5 - Software Testing Methodologies 26-03-2024
15 Module 5 - Software Testing Methodologies 26-03-2024
15 Module 5 - Software Testing Methodologies 26-03-2024
MODULE 5
Software Testing
1
Module:5 Software Testing
2
Testing
3
Software Testing
• One of the practical methods commonly used to detect the
presence of errors (failures) in a computer program is
to test it for a set of inputs.
4
Software Testing . . .
7
WHAT IS SOFTWARE TESTING?
8
It is clear from the definition of Testing by
Myers that
04/24/2024 9
Quality Software Should be
Bug Free
Delivered on time
complete
Within budget
Meet the requirement of the customer.
Easy to maintain and upgrade whenever needed.
Can be web enabled
Adaptable to various OS like Unix, Linux etc
Can run in notepads, PCs, Mainframes as per customer
requirements
Documented
Consistency
Secured
10
Why is testing important?
04/24/2024 12
Why does software have bugs?
Miscommunication or no communication
Time pressure(Time Scheduling)
Changing requirements
Software complexity
Programming mistakes
13
Software Testing Principles
14
Principle1:-Testing shows the
presence of defects
Suppose you have 15 input fields to test each having 5
possible values,the number of combinations to be
tested would be 5^15=30517578125!!
15
Principle2-Exhaustive testing is
impossible
If you were to test all the possible
combinations, projects execution time and costs
will rise exponentially
We have learned that we cannot test everything
(i.e. all combinations of inputs and pre-
conditions).
That is, we must Prioritise our testing effort
using a Risk Based Approach.
16
Principle3 – Early Testing
17
Principle 4:-Defect Clustering
18
Principle 5:-Pesticide Paradox
5. The Pesticide Paradox
Testing identifies bugs, and programmers
respond to fix them
As bugs are eliminated by the programmers, the
software improves
As software improves the effectiveness of
previous tests erodes
Therefore we must learn, create and use new
tests based on new techniques to catch new bugs
( i.e. It is not a matter of repetition. It is a
matter of learning and improving)
19
Principle:- 6 Testing is Context Dependent
20
Principle7:- Absence of error is
a Fallacy
21
Software Testing - Levels
22
Software Testing - Levels
Process:
Begin by testing the main module and its interactions with
lower-level modules (not yet implemented).
Use stubs (simulated modules) to represent the missing
lower levels and provide expected responses for testing the
higher- level module's logic.
Gradually integrate lower-level modules one by one,
replacing stubs with actual components and refining tests
as the system becomes more complete.
Testing Strategies – Top-Down
Advantages:
Early detection of high-level design flaws.
Verifies system-level functionality early in development.
Facilitates a u ser-centric approach, testing featu res as the
u ser would experience them.
Disadvantages:
Requ ires creation and m aintenance of stu bs, which
can be time- consuming.
May be difficult to isolate issues that arise from interactions
between lower-level components.
Testing Strategies – Top-Down
Example:
Imagine testing a new online store. Top-down testing
would start with simulating user actions like browsing
products, adding items to the cart, and checking out.
You'd use stubs to represent payment processing
and inventory management until those modules are
developed
Testing Strategies – Bottom-Up
Process:
S tart by testing individu a l modu les or u n its in
isolation , ensuring they function as per specifications.
G radu a lly integrate tested modu les into sm all
grou ps (clusters) and test their interactions.
Continue integrating clusters to form larger
subsystems
and eventu ally the entire system, testing
fun ction ality at each stage.
Testing Strategies – Bottom-Up
Advantages:
Promotes reusability of unit tests for individual
modules.
E asier to isolate and pinpoint bugs
originating from specific modules.
Disadvantages:
System-level functionality might not be tested until
later stages.
Requires careful design of interfaces between modules
Example:
Testing the online store from the bottom up might
involve first testing individual modules like product
search, shopping cart logic, and user
authentication. Then, you'd combine them to test
adding items to the cart and user checkout.
Testing Strategies – Thread Testing
Process:
Identify potential thread-related issues like race conditions
(unexpected outcomes due to timing) or deadlocks (threads
waiting on each other indefinitely).
Design test cases to simulate how multiple threads interact
with shared resources like memory or files.
Use tools or techniques like thread synchronization testing
to ensure proper coordination between threads.
Testing Strategies – Thread Testing
Advantages:
Helps to identifyand prevent thread-
related bugs thatmight not be apparent in single-
threaded testing.
Disadvantages:
C a n be complex to design and execute test cases for
multi- threaded scenarios.
Debugging thread-related issues can be challenging.
Testing Strategies – Thread Testing
Example:
Testing a multi-user chat application
would involve thread testing to ensure
messages are sent and received properly
when multiple users chat
simultaneously. You'd want to avoid race
conditions where a message might be
incomplete or out of order.
Testing Strategies – Stress Testing
Process:
S imu late high u ser loads, large data volu mes, or
resou rce exhaustion scenarios.
Monitor system performance metrics like
response times, resource utilization (CPU, memory),
and error rates.
Analyze the resu lts to identify potential bottlenecks
or areas where performance degrades under stress.
Testing Strategies – Stress Testing
Advantages:
Increases confidence in the system's ability to h andle
peak loads or unexpected surges in activity.
Helps improve system scalability and resilience.
Disadvantages:
C a n be resource-intensive to set up and execute stress tests.
Example:
Stress testing the online store might involve simulating a
Process:
Execute the same set of test cases on both systems.
Example
An example of back-to-back testing would be comparing
04/24/2024 49
Parallel Testing
• This approach is done when a new system is replacing
an existing one or is part of a phased development.
04/24/2024 50
Testing Strategies – Regression Testing
Purpose:
• Verify that code modifications haven't
negatively impacted previously working
features.
• Catch regressions early in the
development cycle to minimize rework
and delays.
• Maintain the overall quality and
stability of the software. 52
Testing Strategies – Regression Testing
When to Perform:
• After any code changes, bug fixes, or new feature additions.
Benefits:
• Improves software quality and reliability.
• Reduces the risk of regressions impacting users.
• Increases developer confidence in the stability of the codebase.
• Saves time and resources by catching regressions early.
Challenges:
• Can be time-consuming, especially for full regression testing.
• Maintaining a large and up-to-date test suite can be a burden.
• Deciding on the appropriate level of regression testing for
different scenarios
55
Unit Testing
• Initially, each program component (module) is tested
independently verifying the component functions with the
types of input identified by studying component’s design.
04/24/2024 56
04/24/2024 57
Unit Testing
• Examining the code: Typically the static testing methods like:
04/24/2024 59
Testing program components
• To test a component (module), input data and conditions are
chosen to demonstrate an observable behavior of the code.
04/24/2024 60
Integration Testing
04/24/2024 61
Integration Testing
• Integration is the process of assembling unit-tested modules.
• We need to test the following aspects:
Interfaces: To ensure “interface integrity,” the transfer of data between
modules is tested. When data is passed to another module, by way of a call,
there should not be any loss or corruption of data. The loss or corruption of
data can happen due to miss-match or differences in the number or order of
calling and receiving parameters.
Module combinations may produce a different behavior due to combinations
of data that are not exercised during unit testing.
Global data structures, if used, may reveal errors due to unintended usage in
some module.
04/24/2024 62
Integration Strategies
04/24/2024 63
consider the following arrangement of
modules:
04/24/2024 64
Big Bang approach
04/24/2024 65
• Though Big Bang approach seems to be advantageous
when we construct independent module concurrently,
04/24/2024 66
Incremental approach
• The alternative strategy is an incremental approach, wherein
modules of a system are consolidated with already tested
components of the system.
• In this way, the software is gradually built up, spreading the
integration testing load more evenly through the construction
phase.
• Incremental approach can be implemented in two distinct
ways:
Top-down
Bottom-up.
04/24/2024 67
Top-down Testing
04/24/2024 68
Bottom-up Testing
04/24/2024 69
Top Down Approach
Advantages
• Advantageous if major defects occur toward the top of the program
• Early wasted program allows demonstrations and boosts confidence
Disadvantages
• Stub modules must be produced
• Test conditions may be impossible, or very difficult, to create .
• Observation of test output is more difficult, as only simulated
values will be used initially. For the same reason, program
correctness can be misleading.
04/24/2024 70
Bottom Up Approach
Advantages
• if major defect occur toward the bottom of the program
• Test conditions are easier to create
• Observations of test results is easier (as “live” data is used from
the beginning)
Disadvantages
• Driver modules must be produced
• The program as an entity does not exist until the last module is
added
04/24/2024 71
System Testing
• Once the system is integrated, the overall functionality is tested
against the Software Requirements Specification (SRS).
04/24/2024 72
Acceptance Testing
• The next step is customer’s validation of the system against
User Requirements Specification .
04/24/2024 73
Acceptance Testing
• Acceptance testing is the customer (and user) evaluation
of the system, primarily to determine whether the system
meets their needs and expectations.
• Usually acceptance test is done by customer with
assistance from developers.
• Customers can evaluate the system either by conducting a
benchmark test or by a pilot test.
04/24/2024 74
• In benchmark test, the system performance is evaluated
against test cases that represent typical conditions under
which the system will operate when actually installed.
04/24/2024 75
Sandwich Testing
• To overcome the limitations and to exploit the
advantages of Top-down and Bottom-up testing, a
sandwich testing is used
• This system is viewed as three layers – the target layer
in the middle, the levels above the target, and the levels
below the target.
• A top-down approach is used in the top layer and a
bottom-up one in the lower layer.
04/24/2024 76
• Testing converges on the target layer, chosen on the basis
of system characteristics and the structure of the code.
04/24/2024 77
System Testing
04/24/2024 79
Testing Strategies – Others
Performance Testing:
• This strategy tests the software to determine its
performance characteristics such as speed,
scalability, and stability.
80
Testing Strategies – Others
Security Testing:
• This strategy tests the software to identify
vulnerabilities and ensure it meets security
requirements.
81
White Box Testing
04/24/2024 82
Testing Methods – White Box Testing
Key Characteristics:
• Testers' Skills: Requires programming
knowledge and understanding of the specific
programming language used in the application
being tested.
84
Testing Methods – White Box Testing
Benefits:
• Identifies logic errors, code inefficiencies,
and potential security vulnerabilities.
• Ensures all code paths are exercised and
tested.
• More targeted testing based on the code
structure.
85
Testing Methods – White Box Testing
87
Testing Methods – White Box Testing
Techniques:
89
Testing Methods – White Box Testing
Statement Coverage
Aims to ensure that every single line of
code (executable statement) is executed at
least once during testing.
Testing Methods – White Box Testing
Statement Coverage
def calculate_area(length, width):
if length < 0 or width < 0:
return "Invalid dimensions. Length and width must be non-negative."
else:
area = length * width
return area
Testing Methods – White Box Testing
Statement Coverage
Test Case 1: calculate_area(2, 3) (Executes all
lines, returns 6)
Branch Coverage
Focuses on ensuring that each possible outcome
of a conditional statement (branch) is executed at least
once.
Example: Using the same calculate_area function :
Test Case 1: (from Statement Coverage) covers the
"valid dimension" branch.
Test Case 3: calculate_area(2, -5) (Executes the
"invalid dimension" branch, returns "Invalid dimensions...")
Testing Methods – White Box Testing
Condition Coverage
Like branch coverage but focuses on
individual conditions within a decision
statement.
Condition Coverage
Example - Imagine a function that checks if a
number is even or odd:
def is_even(number):
return number % 2 == 0
Testing Methods – White Box Testing
Condition Coverage
Test Case 1: is_even(4) (Condition number % 2
== 0 evaluates to True, returns True)
V(G) = E - N + 2P
Cyclomatic complexity (CC) = E - N + 2P
Where:
V(G) – Given graph
P = number of disconnected parts of the flow graph (e.g. a
calling program and a subroutine)
E = number of edges (transfers of control)
N = number of nodes (sequential group of statements containing
only one transfer of control)
04/24/2024 110
• McCabe’s Number = No. of Regions (Count the mutually exclusive
closed regions and also the whole outer space as one region) = 2 (in the
above graph)
• Two other formulae as given below also define the above measure:
McCabe’s Number = E - N +2
( = 6 – 6 +2 = 2 for the above graph)
• McCabe’s Number = P + 1
( =1 + 1= 2 for the above graph)
• Please note that if the number of conditions is more than one in a
single control structure, each condition needs to be separately
marked as a node.
• When the McCabe’s number is 2, it indicates that there two linearly
independent paths in the code. i.e., two different ways in which the graph
can be traversed from the 1st node to the last node
• The independents in the above graph are:
i) 1-2-3-5-6
ii) 1-2-4-5-6
• The last step is to write test cases corresponding to the
listed paths.
• This would mean giving the input conditions in such a
way that the above paths are traced by the control of
execution.
The test cases for the paths listed here are shown in the
following table.
Input Actual
Path Condition Expected Result Result Remarks
04/24/2024 115
Prepare a Test Case Table
Input Actual
Path Condition Expected Result Result Remarks
i)
ii)
Ex 1 : Compute the Cyclomatic Complexity of
the given program
Cyclomatic Complexity
= E – N + 2p
= 9 – 7 + 2*1
=4
OR
Cyclomatic Complexity
= 3+1(Condition nodes are 1,2 and 3 nodes)
=4
Ex 2 : Compute the Cyclomatic Complexity
of the given program
begin
int a, b, p, temp;
float c;
input(a, b);
if(b<0) Procedure :
temp = -b;
else • First draw the control
temp = b; flow graph for the given
c=1; code-
while(temp!=0)
{ c=c*p; • Compute the CC
temp=temp-1;
}
if(b<0)
c=1/c;
output(c);
end
Control flow graph
Cyclomatic Complexity
= E – N + 2p
= 16 – 14 + 2*1
=4
121
Black box Testing
04/24/2024 122
Equivalence Partitioning
• Equivalence partitioning is partitioning the input domain
of a system into finite number of equivalent classes .
• To put this in simpler words, since it is practically
infeasible to do complete testing, the next best alternative
is to check whether the program extends similar behavior
or treatment to a certain group of inputs.
• If such a group of values can be found in the input
domain treat them together as one equivalent class and
test one representative from this.
Example
Consider a program which takes “Salary” as input with
values 12000...37000 in the valid range.
The program calculates tax as follows:
- Salary up to Rs. 15000 – No Tax
- Salary between 15001 and 25000 – Tax is 18 % of Salary
- Salary above 25000 – Tax is 20% of Salary
Accordingly, the valid input domain can be
divided into three valid equivalent classes as
below:
c1 : values in the range 12000...15000
c2: values in the range 15001...25000
c3: values > 25000
• However, it is not sufficient that we test only valid test
cases.
• We need to test the program with invalid data also as the
users of the program may give invalid inputs,
intentionally or unintentionally.
• It is easy to identify an invalid class
“c4: values < 12000”.
Equivalent classes identified
Summary
To design test cases using equivalence
partitioning, for a range of valid input values
identify
• one valid value within the range
• one invalid value below the range and
• one invalid value above the range
Example
• Similarly, To design test cases for a specific set of values
• one valid case for each value belonging to the set
• one invalid value
• Test Cases for Types of Account (Savings, Current) will be
• Savings, Current (valid cases)
• Overdraft (invalid case)
• It may be noted that we need fewer test cases if some test
cases can cover more than one equivalent class.
II. Boundary Value Analysis
• Even though the definition of equivalence
partitioning states that testing one value from a class
is equivalent to testing any other value from that
class, we need to look at the boundaries of
equivalent classes more closely. This is so since
boundaries are more error prone.
II. Boundary Value Analysis
To design test cases using boundary value analysis, for a
range of values,
• Two valid cases at both the ends
• Two invalid cases just beyond the range limits
The test cases using boundary value analysis
are
III. Cause Effect Analysis
• The main drawback of the previous two techniques is that they do not
explore the combination of input conditions.
04/24/2024 136
Cause Effect Graphing Eg..
Contd.,
Consider the following specification:
A program accepts Transaction Code - 3 characters as input.
For a valid input the following must be true.
1st character (denoting issue or receipt)
+ for issue
- for receipt
2nd character - a digit
3rd character - a digit
V. Error Guessing