My Unit4
My Unit4
SOFTWARE TESTING
Topics to cover
• Testing Objectives
• Unit Testing (Test Drivers and Test Stubs), Integration testing, Acceptance
testing, Regression Testing
• Testing for functionality and testing for performance.
• Top Down and Bottom up testing strategies:
• White Box testing /Structural Testing
• Functional Testing/Black Box Testing
• Test Data Suit preparation, Alpha and Beta testing of products.
• Static Testing Strategies:
• Formal technical Reviews (Peer reviews)
• Walk Through
• Code Inspection
• Compliance with Design and Coding standards.
What is Testing?
• “Testing is the process of executing a program with the intent of finding errors.”
• Testing a program consists of providing the program with a set of test inputs (or test cases) and
observing if the program behaves as expected.
• If the program fails to behave as expected, then the conditions under which failure occurs are
noted for later debugging and correction.
• Some commonly used terms associated with testing are:
i. Failure: This is a manifestation of an error (or defect or bug). But, the mere presence of an
error may not necessarily lead to a failure.
ii. Test case: This is the triplet [I,S,O], where I is the data input to the system, S is the state of the
system at which the data is input, and O is the expected output of the system.
iii. Test suite: This is the set of all test cases with which a given software product is to be tested.
Aim of testing
• The aim of the testing process is to identify all defects existing in a software product.
• It is not possible to guarantee that the software is error free.
• This is because the input data domain of most software products is very large. It is not practical to
test the software exhaustively with respect to each value that the input data may assume.
• Even with this practical limitation of the testing process, the importance of testing should not be
underestimated.
• Testing provides a practical way of reducing defects in a system and increasing the users’
confidence in a developed system.
Software Testing Principles
• Software testing is a procedure of implementing software or the application to identify the defects or
bugs.
• For testing an application or software, we need to follow some principles to make our product defects
free, and that also helps the test engineers to test the software with their effort and time.
Software Testing Principles: 1. Testing shows the
presence of defects
• The test engineer will test the application to make sure that the application is bug or defects free.
• While doing testing, we can only identify that the application or software has any errors.
• The primary purpose of doing testing is to identify the numbers of unknown bugs with the help of
various methods and testing techniques because the entire test should be traceable to the
customer requirement, which means that to find any defects that might cause the product failure
to meet the client's needs.
• By doing testing on any application, we can decrease the number of bugs, which does not mean
that the application is defect-free because sometimes the software seems to be bug-free while
performing multiple types of testing on it.
Software Testing Principles:
Exhaustive Testing is not possible
• Sometimes it seems to be very hard to test all the modules and their features with effective and
non- effective combinations of the inputs data throughout the actual testing process.
• Hence, instead of performing the exhaustive testing as it takes boundless determinations and
most of the hard work is unsuccessful.
• So we can complete this type of variations according to the importance of the modules because
the product timelines will not permit us to perform such type of testing scenarios.
Software Testing Principles: Early
Testing
• Here early testing means that all the testing activities should start in the early stages of the
software development life cycle's requirement analysis stage to identify the defects because if
we find the bugs at an early stage, it will be fixed in the initial stage itself, which may cost us very
less as compared to those which are identified in the future phase of the testing process.
• To perform testing, we will require the requirement specification documents; therefore, if the
requirements are defined incorrectly, then it can be fixed directly rather than fixing them in
another stage, which could be the development phase.
Software Testing Principles: Defect
clustering
• The defect clustering defined that throughout the testing process, we can detect the numbers of
bugs which are correlated to a small number of modules.
• We have various reasons for this, such as the modules could be complicated; the coding part may
be complex, and so on.
• These types of software or the application will follow the Pareto Principle, which states that we
can identify that approx.
• Eighty percent of the complication is present in 20 percent of the modules.
• With the help of this, we can find the uncertain modules, but this method has its difficulties if the
same tests are performing regularly, hence the same test will not able to identify the new defects.
Software Testing Principles: Pesticide
paradox
• This principle defined that if we are executing the same set of test cases again and again over a
particular time, then these kinds of the test will not be able to find the new bugs in the software
or the application.
• To get over these pesticide paradoxes, it is very significant to review all the test cases frequently.
• And the new and different tests are necessary to be written for the implementation of multiple
parts of the application or the software, which helps us to find more bugs.
Software Testing Principles: Testing
is context-dependent
• Testing is a context-dependent principle states that we have
multiple fields such as e-commerce websites, commercial
websites, and so on are available in the market.
• There is a definite way to test the commercial site as well as
the e-commerce websites because every application has its
own needs, features, and functionality.
• To check this type of application, we will take the help of
various kinds of testing, different technique, approaches,
and multiple methods. Therefore, the testing depends on
the context of the application.
Software Testing Principles: Absence
of errors fallacy
• Once the application is completely tested and there are no bugs identified before the release, so
we can say that the application is 99 percent bug-free.
• But there is the chance when the application is tested beside the incorrect requirements,
identified the flaws, and fixed them on a given period would not help as testing is done on the
wrong specification, which does not apply to the client's requirements.
• The absence of error fallacy means identifying and fixing the bugs would not help if the
application is impractical and not able to accomplish the client's requirements and needs.
Software Testing
• Software testing can be divided into two steps:
1. Verification: it refers to the set of tasks that ensure
that software correctly implements a specific function.
2. Validation: it refers to a different set of tasks that
ensure that the software that has been built is traceable
to customer requirements.
Verification: “Are we building the product right?”
Validation: “Are we building the right product?”
Methods of Software Testing
white-box black-box
methods methods
Methods
Strategies
Black-Box Testing
requirements Comparison
output
input events
Black-Box Testing
• Black box design treats the system as a black-box.
• It is also known as Functional Testing, Behavioral Testing,
Data-Driven Testing, Input/Output driven Testing.
• Give input to the system, get the output, compare the
output with the specification, if it matches, then the
system is fine, otherwise error is there.
• Black-Box testing attempts to uncover the following
Incorrect functions
Missing functions
Performance errors
Initialization & Termination errors
External Database access errors.
White-Box Testing
AAAAAA
BBBBBB
CCCC
DDDDD
input
White-Box Testing
• Also known as Structural Testing, Clear-Box Testing, Open-
Box Testing, Logic-Driven Testing.
• Using White-Box testing methods, the software engineer
can derive test cases that.
Guarantee that all independent paths within a module have
been exercised at least once.
Exercise all logical decisions on their true and false sides.
Execute all loops at their boundaries and within their
operational bounds.
Exercise internal data structures to ensure their validity.
Also known as closed box/data driven testing. Also knwon as clear box/structural testing.
End users, testers and developers. Normally done by testers and developers.
THis can only be done by trial and error method. Data domains and internal boundaries can be
better tested.
Software Testing Life Cycle
system
specification test
detailed integration
design test
implementation unit
code test
Unit Testing
• Involves testing a single isolated module
• Note that unit testing allows us to isolate the errors to a single module
• we know that if we find an error during unit testing it is in the module
we are testing
• Modules in a program are not isolated, they interact with each other.
Possible interactions:
• calling procedures in other modules
• receiving procedure calls from other modules
• sharing variables
• For unit testing we need to isolate the module we want to test, we do this
using two things
• drivers and stubs
Drivers and Stubs
Module
Driver Stub
procedure Under Test procedure
call call
access to global
variables
• Driver and Stub should have the same interface as the modules they replace
• Driver and Stub should be simpler than the modules they replace
Drivers and Stubs
• Driver: A program that calls the interface procedures of the
module being tested and reports the results
level 1 C H
level 0 E F G I
• Requires a module driver for each module to feed the test case
input to the interface of the module being tested
• However, stubs are not needed since we are starting with the
terminal modules and use already tested modules when
testing modules in the lower levels
Bottom-up Integration
A B
C H
E F G I
Top-down Integration
• Only modules tested in isolation are the modules which are at
the highest level
A B
C
H
E F G I
Other Approaches to
Integration
• Sandwich Integration
• Compromise between bottom-up and top-down testing
• Simultaneously begin bottom-up and top-down testing and meet at a
predetermined point in the middle
• Instead of completely going for top down or bottom up, a layer is
identified in between.
• Above this layer we go for top down and below this layer bottom up.
• Sanity Testing
• It is used to ensure that all the bugs have been fixed and no added
issues come into existence due to these changes. Sanity testing is
unscripted, which means we cannot document it. It checks the
correctness of the newly added features and components.
Regression Testing
• Regression testing is the most commonly used type of software testing. Here,
the term regression implies that we have to re-test those parts of an
unaffected application.
• Regression testing is the most suitable testing for automation tools. As per the
project type and accessibility of resources, regression testing can be similar
to Retesting.
• Whenever a bug is fixed by the developers and then testing the other features
of the applications that might be simulated because of the bug fixing is known
as regression testing.
• In other words, we can say that whenever there is a new release for some
project, then we can perform Regression Testing, and due to a new feature
may affect the old features in the earlier releases.
Exploratory Testing
• Whenever the requirement is missing, early iteration is required, and
the testing team has experienced testers when we have a critical
application. New test engineer entered into the team then we go for
the exploratory testing.
• To execute the exploratory testing, we will first go through the
application in all possible ways, make a test document, understand
the flow of the application, and then test the application.
Adhoc Testing
• Testing the application randomly as soon as the build is in the checked
sequence is known as Adhoc testing.
• It is also called Monkey testing and Gorilla testing. In Adhoc testing,
we will check the application in contradiction of the client's
requirements; that's why it is also known as negative testing.
• When the end-user using the application casually, and he/she may
detect a bug. Still, the specialized test engineer uses the software
thoroughly, so he/she may not identify a similar detection.
• Security Testing
• It is an essential part of software testing, used to determine the
weakness, risks, or threats in the software application.
• The execution of security testing will help us to avoid the nasty
attack from outsiders and ensure our software applications'
security.
• In other words, we can say that security testing is mainly used to
define that the data will be safe and endure the software's working
process.
• Globalization Testing
• It is used to check the developed software supports multiple
languages and multiple features in all languages.
• In present scenarios, we can see the enhancement in several
technologies as the applications are prepared to be used globally.
User Acceptance Testing
• Static testing techniques offer a great way to enhance the quality and
efficiency of software development. The Static testing technique can
be done in two ways, which are as follows:
• Review
• Static Analysis
• Review
• In static testing, the review is a technique or a process implemented to find
the possible bugs in the application. We can easily identify and eliminate
faults and defects in the various supporting documents such as SRS [Software
Requirements Specifications] in the review process.
• In other words, we can say that a review in Static Testing is that where all the
team members will understand about the project's progress.
Static Analysis
• Another Static Testing technique is static analysis, which is used to contain
the assessment of the code quality, which is established by developers.
• We can use the different tools to perform the code's analysis and
evaluation of the same.
• In other words, we can say that developers' developed code is analyzed
with some tools for structural bugs, which might cause the defects.
• The static analysis will also help us to identify the below errors:
• Dead code
• Unused variables
• Endless loops
• Incorrect syntax
• Variable with undefined value
Formal Technical
Reviews
• Formal Technical Reviews are conducted by software engineers.
• The primary objective is to find errors during the process so that they do not
become defects after release of software as they uncover errors in function, logic
design, or implementation.
• The idea is to have early discovery of errors so they do not propagate to the next
step in the process.
• They also ensure that the software has been represented according to predefined
standards and it is developed in a uniform manner.
• They make projects more manageable and help groom new resources as well as
provide backup and continuity.
Formal Technical Reviews
(Contd.)
• FTRs are usually conducted in a meeting that is successful only if it
is properly planned, controlled.
• The producer informs the Project Manager that the Work Product
is ready and the review is needed.
• The review meeting consists of 3-5 people and advanced
preparation is required.
• It is important that this preparation should not require more than 2
hours of work per person.
• It should focus on specific (and small) part of the overall software.
• For example, instead of the entire design, walkthroughs are
conducted for each component, or small group of components. By
narrowing focus, FTR has a high probability of uncovering errors.
Formal Technical Reviews (Contd.)
• It is important to remember that the focus is on a work
product (WP) for which the producer of the WP asks the
project leader for review.
• Project leader informs the review leader.
• The review leader evaluates the WP for readiness and if
satisfied generates copies of review material and
distributes to reviewers for advanced preparation.
Formal Technical Reviews Review
Meetings (Contd.)
• Review meeting (RM) is attended by the review leader, all reviewers, and the
producer.
• One of the reviewer takes the roles of recorder.
• Producer walks through the product, explaining the material while other
reviewers raise issues based upon their advanced preparation.
• When valid problems or errors are recorded, the recorder notes each one of
them.
• At the end of the RM, all attendees of the meeting must decide whether to:
Accept the product without further modification
Formal Technical Reviews Review
Meetings (Contd.)
• Reject the product due to severe errors
– Major errors identified
– Must review again after fixing
• Accept the product provisionally
– Minor errors to be fixed
– No further review
Formal Technical Reviews
Review Reporting and Record
keeping(Contd.)
• During the FTR the recorder notes all the issues.
• They are summarized at the end and a review issue list is prepared.
• A summary report is produced that includes:
• What is reviewed
• Who reviewed it
• What were the findings and conclusions
• It then becomes part of project historical record.
Formal Technical Reviews
(Contd.)
The review issue list
• It is sometimes very useful to have a proper review issue list. It has two objectives.
• Identify problem areas within the WP Action item checklist
• It is important to establish a follow-up procedure to ensure that items on the issue list
have been properly addressed.
Review Guidelines
• It is essential to note that an uncontrolled review can be worse than no review.
• The basis principle is that the review should focus on the product and not the
producer so that it does not become personal.
• Errors should be pointed out gently and the tone should be loose and constructive.
Walkthrough
• Do not use a coding style that is too clever or too difficult to understand
• Do not use an identifier for multiple purposes
• The code should be well-documented
• The length of any function should not exceed 10 source lines
• Do not use goto statements
• Do not do hard coding
Techniques to perform Testing
• Black Box Testing • White Box Testing
• Boundary Value Analysis • Coverage metrics
• Equivalence class testing • Statement coverage: all statements in
• Cause Effect Graphing Technique the programs should be executed at
least once
• Decision Table Based Testing
• Branch coverage: all branches in the
program should be executed at least
once
• Path coverage: all execution paths in
the program should be executed at lest
once
• The best case would be to execute
all paths through the code
Equivalence Class Partitioning
• Equivalence partitioning (EP) is a specification-based or black-box technique.
• It can be applied at any level of testing and is often a good technique to use
first.
• The idea behind this technique is to divide (i.e. to partition) a set of test
conditions into groups or sets that can be considered the same (i.e. the system
should handle them equivalently), hence ‘equivalence
partitioning’. Equivalence partitions are also known as equivalence classes –
the two terms mean exactly the same thing.
• In equivalence-partitioning technique we need to test only one condition from
each partition.
• This is because we are assuming that all the conditions in one partition
will be treated in the same way by the software.
• If one condition in a partition works, we assume all of the conditions in
that partition will work, and so there is little point in testing any of these
others.
• Similarly, if one of the conditions in a partition does not work, then we
assume that none of the conditions in that partition will work so again
there is little point in testing any more in that partition.
Guidelines for Equivalence Class
Partitioning
• If the range condition is given as an input, then one valid and two invalid equivalence classes are defined.
• If a specific value is given as input, then one valid and two invalid equivalence classes are defined.
• If a member of set is given as an input, then one valid and one invalid equivalence class is defined.
• If Boolean no. is given as an input condition, then one valid and one invalid equivalence class is defined.
Equivalence Class Partitioning
(Contd.)
• If testing is done for an input box accepting numbers
from 1 to 1000 then there is no use in writing
thousand test cases for all 1000 valid input numbers
plus other test cases for invalid data.
• Using equivalence partitioning method above test
cases can be divided into three sets of input data
called as classes. Each test case is a representative of
respective class.
• So in above example we can divide our test cases into
three equivalence classes of some valid and invalid
inputs.
Equivalence Class Partitioning
(Contd.)
• Test cases for input box accepting numbers between 1 and
1000 using Equivalence Partitioning:
1) One input data class with all valid inputs. Pick a single value
from range 1 to 1000 as a valid test case. If you select other
values between 1 and 1000 then result is going to be same. So
one test case for valid input data should be sufficient.
2) Input data class with all values below lower limit. I.e. any
value below 1, as a invalid input data test case.
3) Input data with any value greater than 1000 to represent third
invalid input class.
• So using equivalence partitioning you have categorized all possible
test cases into three classes. Test cases with other values from any
class should give you the same result.
Equivalence Class Partitioning (Contd.)
• Let us consider an example of an online shopping site. In this site, each of products has specific
product ID and product name. We can search for product either by using name of product or by
product ID. Here, we consider search field that accepts only valid product ID or product name.
• Let us consider set of products with product IDs and user want to search for Mobiles. Below is table
of some products with their product Id.
• If the product ID entered by user is invalid then application will redirect customer or user to error
page. If product ID entered by user is valid i.e. 45 for mobile, then equivalence partitioning method
will show a valid product ID.
Boundary Value Analysis
• It’s widely recognized that input values at the extreme ends of input domain
cause more errors in system.
• More application errors occur at the boundaries of input domain.
• ‘Boundary value analysis’ testing technique is used to identify errors at
boundaries rather than finding those exist in center of input domain.
• Boundary value analysis is a next part of Equivalence partitioning for designing
test cases where test cases are selected at the edges of the equivalence classes.
Boundary Value Analysis
(Contd.)
• Test cases for input box accepting numbers between
1 and 1000 using Boundary value analysis:
1) Test cases with test data exactly as the input
boundaries of input domain i.e. values 1 and 1000 in
our case.
2) Test data with values just below the extreme edges
of input domains i.e. values 0 and 999.
3) Test data with values just above the extreme edges
of input domain i.e. values 2 and 1001.
• Boundary value analysis is often called as a part of stress and
negative testing.
Boundary Value Analysis
Causes are
c1: character in column1 is A
c2: character in column1 is B
c3: character in column2 is a digit
Effects are:
Cause-Effect Graphs (Contd.)
Cause-Effect Graphs (Contd.)
Cause-Effect Graphs (Contd.)
Coverage Metrics: White Box Testing Techniques
• Coverage metrics
• Statement coverage: all statements in the programs should
be executed at least once
• Branch coverage: all branches in the program should be
executed at least once
• Path coverage: all execution paths in the program should
be executed at least once
• The best case would be to execute all paths through
the code
Read P
Read Q
IF P+Q > 100 THEN
Print “Large”
ENDIF
If P > 50 THEN
Print “P Large”
ENDIF
Statement Coverage (SC):
To calculate Statement Coverage, find out the shortest number of paths following which all the
nodes will be covered. Here by traversing through path 1A-2C-3D-E-4G-5H all the nodes are
covered. So by traveling through only one path all the nodes 12345 are covered, so the Statement
coverage in this case is 1.
Branch Coverage (BC):
To calculate Branch Coverage, find out the minimum number of paths which will ensure covering
of all the edges. In this case there is no single path which will ensure coverage of all the edges at
one go. By following paths 1A-2C-3D-E-4G-5H, maximum numbers of edges (A, C, D, E, G and H)
are covered but edges B and F are left. To covers these edges we can follow 1A-2B-E-4F. By the
combining the above two paths we can ensure of traveling through all the paths. Hence Branch
Coverage is 2. The aim is to cover all possible true/false decisions.
Path Coverage (PC):
Path Coverage ensures covering of all the paths from start to end.
All possible paths are-
1A-2B-E-4F
1A-2B-E-4G-5H
1A-2C-3D-E-4G-5H
1A-2C-3D-E-4F
So path coverage is 4.
Thus for the above example SC=1, BC=2 and PC=4.
Statement Coverage
if (x < y) { B0 (x < y)
x = 5 * y; Y N
x = x + 3;
} x = 5 * y B1 B2 y = 5
else x = x + 3
y = 5;
x = x+y;
x = x+y B3
• Select a test set T such that by executing program P for each test case
d in T, each edge of P’s control flow graph is traversed at least once
B0
(x < 0)
true false
B1 Test set {x=1} does not
x := -x execute this edge, hence, it
does not give branch coverage
B2
z := x
Path Coverage
• Select a test set T such that by executing program P for
each test case d in T, all paths leading from the initial to
the final node of P’s control flow graph are traversed
Path Coverage
B0
areTheyPositive(int x, int y)
(x >= 0)
{
if (x >= 0) true false
print(“x is positive”); B1 B2
else print(“x is p”) print(“x is n”)
print(“x is negative”);
if (y >= 0)
print(“y is positive”); B3
else (y >= 0)
print(“y is negative”); true false
} B4 B5
Test set: print(“y is p”) print(“y is n”)
T2 = {(x = 12,y = 5), (x = 1,y = 35)}
gives both branch and statement B6
coverage but it does not give path coverage
return
Set of all execution paths: {(B0,B1,B3,B4,B6), (B0,B1,B3,B5,B6), (B0,B2,B3,B4,B6),
(B0,B2,B3,B5,B6)}
Test set T2 executes only paths: (B0,B1,B3,B5,B6) and (B0,B2,B3,B4,B6)
Path Coverage
B0
areTheyPositive(int x, int y)
(x >= 0)
{
if (x >= 0) true false
print(“x is positive”); B1 B2
else print(“x is p”) print(“x is n”)
print(“x is negative”);
if (y >= 0) B3
print(“y is positive”);
else (y >= 0)
print(“y is negative”); true false
} B4 B5
print(“y is p”) print(“y is n”)
Test set:
T1 = {(x=12,y=5), (x=1,y=35),
B6
(x=115,y=13),(x=91,y=2)}
return
gives both branch, statement and path
coverage
Cyclomatic Complexity
• Cyclomatic complexity of a code section is the quantitative measure of the number of linearly
independent paths in it.
• It is a software metric used to indicate the complexity of a program.
• It is computed using the Control Flow Graph of the program.
• The nodes in the graph indicate the smallest group of commands of a program, and a directed
edge in it connects the two nodes i.e. if second command might immediately follow the first
command.
• M=E–N+2
• where,
E = the number of edges in the control flow graph
N = the number of nodes in the control flow graph
Cyclomatic Complexity
• Steps that should be followed in calculating cyclomatic
complexity and test cases design are: