Unit-4
Unit-4
Software Testing
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
under estimated.
• 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.
• Let us see the seven different testing principles, one by one:
1. Testing shows the presence of defects
2. Exhaustive Testing is not possible
3. Early Testing
4. Defect Clustering
5. Pesticide Paradox
6. Testing is context-dependent
7. Absence of errors fallacy
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.
• But at the time of deployment in the production server, if the end-user encounters those bugs
which are not found in the testing process.
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’s or the applications 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 known 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.
Test process in software
development
V-model:
acceptance
requirements test
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
• STUBS
Drivers and Stubs
Module
Driver Stub
procedure Under Test procedure
call call
access to global
variables
A driver simulates a module that calls the module currently being tested
• Stub: A program that has the same interface as a module that is being used by
the module being tested, but is simpler.
• In this Bottom Up approach the lower level modules are tested first
after lower level modules the higher level modules are tested.
• Then these modules undergo for integration accordingly.
• Here the lower level modules refers to sub modules and higher level
modules refers to main modules.
• This approach uses test drivers which are mainly used to initiate and
pass the required data to the sub modules means from higher level
module to lower level module if required.
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.
• Smoke testing, also known as “Build Verification Testing” or “Build Acceptance Testing,” is a type of software
testing that is typically performed at the beginning of the development process to ensure that the most critical
functions of a software application are working correctly. It is used to quickly identify and fix any major issues
with the software before more detailed testing is performed. The goal of smoke testing is to determine whether
the build is stable enough to proceed with further testing.Smoke testing covers most of the major functions of
the software but none of them in depth.
• The result of this test is used to decide whether to proceed with further testing.
• If the smoke test passes, go ahead with further testing. If it fails, halt further tests and ask for a new build with
the required fixes.
• If an application is badly broken, detailed testing might be a waste of time and effort.
• Smoke test helps in exposing integration and major problems early in the cycle.
• It can be conducted on both newly created software and enhanced software.
• Smoke test is performed manually or with the help of automation tools/scripts. If builds are prepared
frequently, it is best to automate smoke testing.
Usability Testing
• USABILITY TESTING is a type of software testing done from an end-user’s perspective to
determine if the system is easily usable. It falls under non-functional testing.
• Usability Testing uses the Black Box Testing method where internal structure of the system is
unknown and is always executed manually because of the need for human interaction and
perception.
Security Testing
• SECURITY TESTING is a type of software testing that intends to uncover vulnerabilities of the
system and determine that its data and resources are protected from possible intruders. It is a
type of non-functional testing.
• There are four main focus areas to be considered in security testing (Especially for web
sites/applications):
• Network security: This involves looking for vulnerabilities in the network infrastructure
(resources and policies).
• System software security: This involves assessing weaknesses in the various software (operating
system, database system, and other software) the application depends on.
• Client-side application security: This deals with ensuring that the client (browser or any such
tool) cannot be manipulated.
• Server-side application security: This involves making sure that the server code and its
technologies are robust enough to fend off any intrusion.
Performance Testing
• PERFORMANCE TESTING is a type of software testing that intends to determine how a system
performs in terms of responsiveness and stability under a certain load. It is a type of non-
functional testing.
• Performance Testing mainly focuses on the following software quality attributes:
• Responsiveness: The ability of software to respond quickly or complete assigned tasks within a
reasonable time.
• Concurrency: The ability of software to service multiple requests to the same resources at the
same time.
• Reliability: The ability of software to perform a required function under stated conditions for the
stated period of time without any errors.
• Stability: The ability of software to remain stable under varying loads or over time.
• Scalability: The measure of software’s ability to increase or decrease in performance in response
to changes in software’s processing demands.
LOAD Testing
• Load testing is used to identify whether the infrastructure used for hosting the application
is sufficient or not
• It is used to find if the performance of the application is sustainable when it is at the peak of its
user load
• It tells us how many simultaneous users can the application handle and the scale of the
application required in terms of hardware, network capacity etc., so that more users could access
the application
• It helps to identify the maximum operating capacity of an application as well as
any bottlenecks and determine which element is causing degradation. E.g. If the number of
users are increased then how much CPU, memory will be consumed, what is the network and
bandwidth response time.
Stress Testing
• It is a type of non-functional testing
• It involves testing beyond normal operational capacity, often to a breaking point, in order to
observe the results
• It is a form of software testing that is used to determine the stability of a given system
• It put greater emphasis on robustness, availability and error handling under a heavy load, rather
than on what would be considered correct behavior under normal circumstances
• The goals of such tests may be to ensure the software does not crash in conditions of insufficient
computational resources (such as memory, disk space, network request etc)
• Stress testing is also called fatigue testing
• The main purpose of stress testing: Make sure that the system fails and recovers easily, this
quality is also known as recoverability.
Acceptance Testing
• 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.
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.
BOUNDARY VALUE ANALYSIS
• Focus on input values and design test cases with input values that are
on or close to boundary values.
There is no need to select all 100 inputs and execute the program one by
one for all 100 inputs.
The number of inputs selected by BVA technique is 4n + 1 where ‘n’ is
the number of inputs.
• Consider a program ‘Addition’ with two input values x and y and it gives the
addition of x and y as an output. The range of both input values are given as:
x ranges from 100 to 300
y ranges from 200 to 400
We also consider ‘single fault’ assumption theory of reliability which says that failures
are rarely the result of the simultaneous occurrence of two (or more) faults.
• Normally, one fault is responsible for one failure.
• With this theory in mind, we select one input value on boundary (minimum), just
above boundary (minimum +), just below boundary (maximum –), on boundary
(maximum), nominal (average) and other n-1 input values as nominal values.
Test Cases
CAUSE-EFFECT GRAPHING TECHNIQUE
• Two new terms are used here and these are causes and effects,
The AND and OR functions are allowed to have any number of inputs.
Design of Limited Entry Decision Table
• The cause-effect graph represents the relationships amongst the causes
and effects.
• This graph may also help us to understand the various
conditions/combinations amongst the causes and effects.
• These conditions/combinations are converted into the limited entry
decision table.
• Each column of the table represents a test case.
Writing of Test Cases
• Each column of the decision table represents a rule and gives us a test
case.
• We may reduce the number of columns with the proper selection of
various conditions and expected actions.
Exclusive constraint or E-constraint: This constraint exists
between causes. It states that either c1 or c2 can be 1, i.e., c1 and c2
cannot be 1 simultaneously.
Inclusive constraint or I-constraint: This constraint exists between causes. It states
that atleast one of c1, c2 and c3 must always be 1, i.e., c1, c2 and c3 cannot be 0
simultaneously.
One and Only One constraint or O-constraint: This constraint exists
between causes. It states that one and only one of c1 and c2 must be 1.
1.Requires constraint or R-constraint: This constraint exists between
causes. It states that for c1 to be 1, c2 must be 1. It is impossible for c1 to be 1
and c2 to be 0.
• IF A = 354
Cyclomatic Complexity
• THEN IF B > C
=P+1
• THEN A = B =2+1
=3
• ELSE A = C
• END IF
• END IF
• PRINT A
Problem-02:
{ int i, j, k;
for (i=0 ; i<=N ; i++) Cyclomatic Complexity
p[i] = 1; =P+1
for (i=2 ; i<=N ; i++)
{ =3+1
k = p[i]; j=1; =4
while (a[p[j-1]] > a[k] {
p[j] = p[j-1];
j--;
}
p[j]=k;
}
Problem-03:
• V(G) = e – n + 2P = 16 – 15 + 2 = 3 [e=
edges, n=nodes]
(P indicates number
of connected components)
• V(G) = no. of regions = 3
• V(G) =π + 1 = 2 + 1 = 3
Independent Paths
• An independent path in a graph is a path that has at least one new
node or edge in its sequence from the initial node to its final node.
• If there is no repetition of an edge in a path from the initial node to
the final node, then the path is called a simple path.
• The number of edges in a path is called the length of the path.
Hence, independent paths are three and are given as:
(i) 1–7, 10, 13–15
(ii) 1–7, 10–15
(iii) 1–10, 13–15
And not 1-15
1. Statement Coverage
• 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