Software Testing
Software Testing
• People make errors. A good synonym is mistake. This may be a syntax error
or misunderstanding of specifications. Sometimes, there are logical errors.
• When developers make mistakes while coding, we call these mistakes
“bugs”.
• Fault : It is a condition that causes the software to fail to perform its
required function. An error leads to fault. Defect is a good synonym for
fault.
• Failure : It is the inability of a system or component to perform required
function according to its specification.
• A failure occurs when a fault executes. Deviation of the software from its
expected result.
Test case
Verification Validation
VERIFICATION & VALIDATION
• Integration testing
• testing parts of the system by combining the modules
• To find the interface errors
• System testing
• testing of the system as a whole after the integration phase
• Acceptance testing
• testing the system as a whole to find out if it satisfies the requirements specifications
Unit Testing
• return 0;
• }
• Mock objects: Create an object that mimics only the behavior needed
for testing
Integration Testing
• Integration testing: Integrated collection of modules tested as a group or partial
system
• Integration plan specifies the order in which to combine modules into partial
systems
float ACIRCLE()
{
float R;
R=Get_Radius(R);
A=R*R*3.14;
return A;
}
int main(){
int R,L;
float Area;
Area=ACIRCLE(R );
printf(“%d”, Area);
return 0;
}
Module Structure
level 3 A B
• We assume that
the uses hierarchy is
a directed acyclic graph.
level 2 • If there are cycles merge
D them to a single module
C H
level 1
level 0 E F G I
• Only terminal modules (i.e., the modules that do not call other modules)
are tested in isolation
• Modules at lower levels are tested using the previously tested higher level
modules
• 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
• After a module is tested, the modules directly called by that module are
merged with the already tested module and the combination is tested
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
• Functional Testing
• Testing Functionality to be delivered by the system
• Specialized Testing (Testing NFRs)
• Volume testing
• to determine whether the program can handle the required volumes of data, requests,
etc.
• Load/Stress testing
• to identify peak load conditions at which the program will fail to handle required processing
loads within required time spans
• Usability (human factors) testing
• to identify discrepancies between the user interfaces of a product and the human
engineering requirements of its potential users.
• Security Testing
• to show that the program’s security requirements can be subverted
Types of System Tests
• Performance testing
• to determine whether the program meets its performance requirements (eg.
response times, throughput rates, etc.)
• Recovery testing
• to determine whether the system or program meets its requirements for recovery
after a failure
• Installability testing
• to identify ways in which the installation procedures lead to incorrect results
• Configuration Testing
• to determine whether the program operates properly when the software or
hardware is configured in a required manner
• Reliability/availability testing
• to determine whether the system meets its reliability and availability requirements
Acceptance Testing
• Acceptance Testing
• Performed by the customer or end user
• Compare the software to its initial requirements and needs of its end users
• Alpha testing
• conducted at the developer’s site by a User
• tests conducted in a controlled environment
• Beta testing
• conducted at one or more User sites by the end user of the SW
• it is a “live” use of the SW in an environment over which the developer has no
control
Regression testing
• You should preserve all the test cases for a program
• During the maintenance phase, when a change is made to the program, the test
cases that have been saved are used to do regression testing
• figuring out if a change made to the program introduced any faults
• When you find a bug in your program you should write a test case that exhibits
the bug
• Then using regression testing you can make sure that the old bugs do not reappear
Advantages of the V-Model
• O1= Not a triangle, when any of the sides is greater than the sum of
the other
• O2 = Equilateral Triangle
• O 3= Isosceles Triangle
• O 4= Scalene Triangle
Equivalence Class Partitioning
• Some inputs domain test cases can be obtained using the relationship
amongst x,y and z.
• I10={< x,y,z >: x = y = z}
• I11={< x,y,z >: x = y, x <= z}
• I12={< x,y,z >: x = z, x <= y}
• I13={< x,y,z >: y = z, x >=y}
• I14={< x,y,z >: x>= y, x>= z, y >=z}
• I15={< x,y,z >: x = y + z}
• I16={< x,y,z >: x > y +z}
• I17={< x,y,z >: y = x +z}
• I18={< x,y,z >: y > x + z}
• I19={< x,y,z >: z = x + y}
• I20={< x,y,z >: z > x +y}
Boundary Value Analysis
• Control-Flow Testing
• Statement coverage
• Decision coverage
• Condition coverage
• Basis Path Testing
• Statement coverage
• write enough test cases to execute every statement at least once
• Decision coverage
• write test cases to exercise the true and false outcomes of every decision
• Condition coverage
• write test cases such that each condition in a decision takes on all possible
outcomes at least once
• may not always satisfy decision coverage
• The objective of path testing is to ensure that the set of test cases is
such that each path through the program is executed at least once.
• The starting point for path testing is a program flow graph that shows
nodes representing program decisions and arcs representing the flow
of control.
1
1, 2, 5, 6
2 1, 2, 3, 4, 2, 6
1, 2, 3, 4, 2, 3, 4, 2, 5, 6
3
…
Prepare test cases that will force the execution of each path in the basis set.
68
Flow Graph
• 1. V(G) = e – n + 2P
• = 13 – 10 + 2 = 5
• 2. V(G) = + 1
•=4+1=5
• 3. V(G) = number of regions
•=5
Graph Matrices
• A graph matrix is a square matrix with one row and one column for
every node in the graph. The size of the matrix (i.e., the number of
rows and columns) is equal to the number of nodes in the flow graph.
Some examples of graphs and associated matrices are shown in fig.
Graph Matrices
Graph Matrices
Graph Matrices
Graph Matrices
Graph Matrices
• A graph matrix is a square matrix with one row and one
column for every node in the graph. The size of the matrix
(i.e., the number of rows and columns) is equal to the
number of nodes in the flow graph. Some examples of graphs
and associated matrices are shown in fig. 24.
Graph Matrices
Graph Matrices
Loop Testing
• Loop testing is a white-box testing technique that
focuses exclusively on the validity of loop constructs.
Loop Testing-Simple Loop
• The following set of tests can be applied to simple loops, where n is the
maximum number of allowable passes through the loop.
• 1. Start at the innermost loop. Set all other loops to minimum values.
• 2. Conduct simple loop tests for the innermost loop while holding the outer
loops at their minimum iteration parameter (e.g., loop counter) values.
Add other tests for out-of-range or excluded values.
• 3. Work outward, conducting tests for the next loop, but keeping all other
outer loops at minimum values and other nested loops to “typical” values.
• 4. Continue until all loops have been tested.
Loop Testing
• Data flow testing is used to analyze the flow of data in the program.
• State Coverage
• ctor – addDrink(2) - addQtr() – addQtr()
• All- Transition Coverage
• ctor – addDrink(2) - addQtr() – addQtr() – addQtr() – vend()
• ctor – addDrink(2) - addQtr() – addQtr() – retQtrs()
• ctor – addDrink(2) - addQtr() – retQtrs()
• ctor – addDrink(1) - addQtr() – addQtr() – vend()
• All- Transition Pair Coverage
• ctor – addDrink(2)
• ctor – addDrink(2) - addQtr() – addQtr() – vend – addDrink()
• ctor – addDrink(2) - addQtr()
State based coverage criteria's
Regression testing
• You should preserve all the test cases for a program
• During the maintenance phase, when a change is made to the program, the test
cases that have been saved are used to do regression testing
• figuring out if a change made to the program introduced any faults
• When you find a bug in your program you should write a test case that exhibits
the bug
• Then using regression testing you can make sure that the old bugs do not reappear
Test Strategies for
Object-Oriented Software
Test Strategies for
Object-Oriented Software
95
Test Strategies for Object-Oriented Software (continued)
96
System Testing
• Functional Testing
• Testing Functionality to be delivered by the system
• Specialized Testing (Testing NFRs)
• Volume testing
• to determine whether the program can handle the required volumes of data, requests,
etc.
• Load/Stress testing
• to identify peak load conditions at which the program will fail to handle required processing
loads within required time spans
• Usability (human factors) testing
• to identify discrepancies between the user interfaces of a product and the human
engineering requirements of its potential users.
• Security Testing
• to show that the program’s security requirements can be subverted
Acceptance Testing
• Acceptance Testing
• Performed by the customer or end user
• Compare the software to its initial requirements and needs of its end users
• Alpha testing
• conducted at the developer’s site by a User
• tests conducted in a controlled environment
• Beta testing
• conducted at one or more User sites by the end user of the SW
• it is a “live” use of the SW in an environment over which the developer has no
control
Test case Template
Test Case ID Test Case Name Inputs Expected Actual Test Result
output output (Pass/Fail)
103
Debugging Process
104
Debugging Process
• Debugging occurs as a consequence of successful testing
105
Why is Debugging so Difficult?
106
Why is Debugging so Difficult?
(continued)
• The symptom may be a result of timing problems, rather than processing
problems
• It may be difficult to accurately reproduce input conditions, such as
asynchronous real-time information
• The symptom may be intermittent such as in embedded systems involving
both hardware and software
• The symptom may be due to causes that are distributed across a number
of tasks running on different processes
107
Debugging Strategies
108
Strategy #1: Brute Force
• Most commonly used and least efficient method
• The program loaded with print statement to print the intermediate values
will help to identify the error.
• Involves the use of memory dumps, run-time traces, and output statements
• Leads many times to wasted effort and time
1. int i;
1. int i; 2. int sum = 0;
2. int sum = 0; 3. int product = 1;
3. int product = 1; 4. int w = 7;
4. int w = 7; 5. for(i = 1; i < N; ++i) {
5. for(i = 1; i < N; ++i) { 6. sum = sum + i + w;
6. sum = sum + i + w; 7. Printf(“%d”, sum);
7. product = product * i; 8. product = product * i;
8. } 9. Printf(“%d”, product);
9. Printf(“%d”, sum); 10. }
10.Printf(“%d”, product); 11.Printf(“%d”, sum); 109
Strategy #2: Backtracking
110
Strategy #3: Cause Elimination
• Involves the use of induction or deduction and introduces the concept of
binary partitioning
• Induction (specific to general): Prove that a specific starting value is true; then
prove the general case is true
• Deduction (general to specific): Show that a specific conclusion follows from a
set of general premises
• Data related to the error occurrence are organized to isolate potential
causes
• A cause hypothesis is devised, and the aforementioned data are used to
prove or disprove the hypothesis
• Alternatively, a list of all possible causes is developed, and tests are
conducted to eliminate each cause
• If initial tests indicate that a particular cause hypothesis shows promise,
data are refined in an attempt to isolate the bug
111
Strategy #4: Program Slicing
• program slicing is the computation of the set of
program statements, the program slice, that may
affect the values at some point of interest, referred to
as a slicing criterion.
• Program slicing can be used in debugging to locate
source of errors more easily. The static executable slice for criteria
1. int i; (write(sum), sum) is the new
program shown below.
2. int sum = 0;
3. int product = 1;
4. int w = 7; 1. int i;
5. for(i = 1; i < N; ++i) 2. int sum = 0;
{ 3. int w = 7;
6. sum = sum + i + w; 4. for(i = 1; i < N; ++i){
7. product = product * i; 5. sum = sum + i + w;
8. } 6.
9. write(sum); 7. }
10. write(product); 8. write(sum);
Coding Standards
// good
$my_email
->set_from('[email protected]')
->add_to('[email protected]')
->set_subject('Methods Chained')
->set_body('Some long message')
->send();