ST Module-2 Updated
ST Module-2 Updated
Software Testing
(CSA 2010)
IV Semester 2024-25
MODULE-2
Error Guessing
• Based on tester intuition and experience.
• Example:
Bank deposit limits ($5000-$7000) – testing values below and above.
White Box Testing
• A software testing method that examines the internal structure, logic, and
code of an application.
• Requires programming knowledge to design test cases.
• Helps in identifying security vulnerabilities, logic errors, and inefficiencies.
Importance of Code Coverage
• Measures how much of the application's code is tested.
• Ensures that unit tests validate the core functionalities.
• Includes techniques like Statement Coverage, Branch Coverage, Path
Coverage, Decision Coverage, Condition Coverage, and Multiple Condition
Coverage.
Statement Coverage
• Ensures that every statement in the code is executed at least once.
• Helps find dead code and unexecuted statements.
• If the test case does not execute printf(“Sum = %d”, sum);, then statement
coverage is incomplete.
Branch Coverage
• Ensures each possible branch of a control structure (IF-ELSE, loops, switches) is executed.
• Covers both True and False conditions.
• Possible paths:
✅ (x > 0, y > 0)
✅ (x > 0, y <= 0)
✅ (x <= 0)
Decision Coverage
• Ensures that all possible outcomes of control flow statements are tested.
• Covers decision points in IF, SWITCH, WHILE, FOR statements.
• Test Cases:
✅ A = True, B = True
✅ A = True, B = False
✅ A = False, B = True
✅ A = False, B = False
Condition Coverage
• Ensures each condition in a decision is tested separately.
• Unlike decision coverage, it examines individual Boolean conditions.
• There is 18 and 30 are the boundary values that's why tester pays more
attention to these values, but this doesn't mean that the middle values
like 19, 20, 21….27,28, 29 are ignored. Test cases are developed for each
and every value of the range.
Boundary Value Testing
• Any program can be considered to be a function in the
sense that prog. I/p form its domain & prog. o/p form
its range.
• Input domain testing is the best known functional
testing technique.
Boundary Value Analysis
• When function F is implemented as a pogram, the input
variables x1 & x2 will have some boundaries
F(x1, x2), a ≤ x1 ≤ b, c ≤ x2 ≤ d
[a,b] [c,d] are ranges of x1 & x2.
•Input space(domain) of our function F is shown above.
•Any point within the shaded rectangle is a legitimate input to
the
function F.
•Boundary value analysis focuses on the boundary of the input
space to identify test cases.
Cont.,
• Errors tend to occur near the extreme values of an input
variable
• e.g. loop conditions (< instead of ≤), counters
• Basic idea: use input variable values at their minimum (min), just
above the minimum (min+), a nominal value (nom), just below
their maximum (max-), and at their maximum (max).
• Testing tool (T) generates such Test Cases for Properly specified
program. min, min+, max-, max.
Cont.,
• The boundary value analysis test cases are obtained by
holding the values of all but one variable at their nominal
values, and letting that variable assume its extreme
values <x ,x >
1nom 2min
<x1nom, x2min+>
<x1nom, x2nom>
<x1nom, x2max->
<x1nom, x2max>
<x1min, x2nom>
<x1min+, x2nom>
<x1nom, x2nom>
<x1max-, x2nom>
<x1max, x2nom>
1) Example on Boundary Value Analysis Test Case Design Technique:
Equivalence class.
Weak normal equivalence class testing.
Strong normal equivalence class testing.
Weak Robust equivalence class testing.
Strong Robust equivalence class testing.
Equivalence class Testing
• Choose the test case from each of the equivalence classes for
each input variable independently of the other input variable
• Using 1 variable from each equivalence class(interval) in a test
case.
Weak Normal Equivalence class test
cases
X2
x1
a b c d
Strong Normal Equivalence testing
• Multi Fault assumption.
• We need Test cases from each element of the Cartesian product
of the equivalence classes.
• The Cartesian product guarantees that we have a notion of
completeness in two senses
• We cover all the equivalence classes,
• We have 1 of each possible combination of inputs.
Strong Normal Equivalence class test
cases
X2
x1
a b c d
Weak Robust Equivalence class
Testing
• Up to now we have only considered partitioning the
valid input space.
X2
x1
a b c d
Equivalence class Test Cases for Triangle problem
Example-1:
Let us consider an example of any college admission process.
There is college that gives admissions to students based upon
their percentage.
• Consider percentage field that will accept percentage only between 50 to 90 %,
more and even less than not be accepted, and application will redirect user to
error page.
• If percentage entered by user is less than 50 %or more than 90 %, that
equivalence partitioning method will show an invalid percentage
• If percentage entered is between 50 to 90 %, then equivalence partitioning
method will show valid percentage.
Example 2:
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.
Decision Table
• A Decision Table is a tabular representation of inputs versus rules/cases/test
conditions. It is a very effective tool used for both complex software testing
and requirements management.
• Decision table helps to check all possible combinations of conditions for
testing and testers can also identify missed conditions easily. The conditions
are indicated as True(T) and False(F) values.
What is Decision Table Testing?
• Decision table testing is a software testing technique used to test system
behavior for different input combinations.
• This is a systematic approach where the different input combinations and
their corresponding system behavior (Output) are captured in a tabular
form.
• That is why it is also called as a Cause-Effect table where Cause and effects
are captured for better test coverage.
Example 2: How to make Decision Table for Upload Screen
Now consider a dialogue box which will ask the user to upload photo with certain conditions like –
LAB EXERCISES
Exp 1: Design and develop a program in a language of your choice to
solve the triangle problem defined as follows: Accept three integers
which are supposed to be the three sides of a triangle and determine if
the three values represent an equilateral triangle, isosceles triangle,
scalene triangle, or they do not form a triangle at all. Assume that the
upper limit for the size of any side is 10. Derive test cases for your
program based on boundary-value analysis, execute the test cases and
discuss the results.
1 WN1 5 5 5 Equilateral
2 WN2 2 2 3 Isosceles
3 WN3 3 4 5 Scalene
4 WN4 4 1 2 Not a Triangle
5 WR1 -1 5 5 Value of a is not in the range of
permitted values
Conditions
R1 R2 R3 R4 R5 R6 R7 R8 R9 R 10 R 11
C1: a<b+c? F T T T T T T T T T T
C2: b<a+c? -- F T T T T T T T T T
C3: c<a+b? -- -- F T T T T T T T T
C4: a=b? -- -- -- F T T T F F F T
C5: a=c? -- -- -- T F T F T F F T
C6: b=c? -- -- -- T T F F F T F T
Actions Action Entries
a2: Scalene X
a3: Isosceles X X X
a4: Equilateral X
a5: Impossible X X X
Decision table Test Cases for Triangle problem
Expected Output
TC ID Test Case Description a B c Actual Output Status
1 WN 10 10 10 $100 10
2 WR2 -2 40 45 Values of locks Values of locks not in the
not in the range range 1...70
1...70
C1: 1≤locks≤70? F T T T T T
C2: 1≤stocks≤80? -- F T T T T
C3: 1≤barrels≤90? -- -- F T T T
C4: sales>1800? -- -- -- T F F
C5: sales>1000? -- -- -- -- T F
C6: sales≤1000? -- -- -- -- -- T
Actions Action Entries
Problem Definition:
• "Next Date" is a function consisting of three variables like: month, date and year. It returns the date
of next day as output. It reads current date as input date.
The Next Date program takes date as input and checks it for validity. If it is valid, it returns the next date as its
output.
Since BVA yields (4n + 1) test cases according to single fault assumption theory,
hence we can say that the total number of test cases will be (4*3+1)=12+1=13.
The boundary value test cases are
C1: 1 ≤ month ≤ 12
C2: 1 ≤ day ≤ 31
C3: 1900 ≤ year ≤ 2024
STRONG NORMAL EQUIVALENCE TEST CLASS
Decision Table for Nextdate problem
DECISION TABLE TEST CASES
LAB EXERCISES ON
WHITE BOX TESTING
Introduction to White box testing
• It is a testing method in which the internal structure/design/implementation
of the program is being tested.
• Also known as Clear Box Testing, Open Box Testing, Glass Box Testing,
Transparent Box Testing, Code-Based Testing or Structural Testing)
• The tester chooses inputs to exercise paths through the code and determines
the appropriate outputs.
The key principles that assist you in executing white box tests successfully are:
Statement Coverage – ensure every single line of code is tested.
Branch Coverage – ensure every branch (e.g. true or false) is tested.
Path Coverage – ensure all possible paths are tested.
Advantages of White Box
Testing:
Basis path testing is a form of Structural testing (White Box testing). The method devised by
McCabe to carry out basis path testing has four steps. These are:
1. Draw the program graph.
2. Calculate the cyclomatic complexity.
3. Select a basis set of paths.
4. Generate test cases for each of these paths
Cyclomatic complexity is a source code complexity measurement that is being correlated to a
number of coding errors. It is calculated by developing a Control Flow Graph of the code that
measures the number of linearly-independent paths through a program module.
Lab Exercise Complete Binary Search program
PROGRAM GRAPH
BASIS PATHS
DERIVING TEST CASES USING BASIS PATH TESTING
The last step is to devise test cases for the basis paths.
TEST CASES
Expected Output
Actual
TC ID PATHS array elements key Status
Output
Element found
1 1-2-3-8-9 {10.20.30.40.50} 30
in position = 3
Element found
2 1-2-3-4-5-7-2 {10.20.30.40.50} 20
in position = 2
Element found
3 1-2-3-4-6-7-2 {10.20.30.40.50} 40
in position = 4
4 1-2-8-9 NA NA NA NA NA
Exp 8: Design, develop, code and run the program in any suitable
language to implement an absolute letter grading procedure, making
suitable assumptions. Determine the basis paths and using them derive
different test cases, execute these test cases and discuss the test results.
V(G)= E – N + 2 * P = 26-20+2*1 = 8
Basis Paths:
P1 to P8
BASIS PATHS TEST CASES
TCID Basis Path Input Data Actual O/P Expected O/p Status
P1 1-2-3-4-5-20 30 Fail Fail Pass
P2
P3
P4
P5
P6
P7
P8
Exercise: 9 Design, develop, code and run the program in any
suitable language to implement a PRIME NUMBER CHECKING
procedure, making suitable assumptions.
Determine the basis paths and using them derive different test
cases, execute these test cases and discuss the test results.
#include <stdio.h>
int main() {
int n, i, flag = 0;
printf("Enter a positive integer: ");
scanf("%d", &n);
// 0 and 1 are not prime numbers
// change flag to 1 for non-prime number
if (n == 0 || n == 1)
flag = 1;
for (i = 2; i <= n / 2; ++i) {
// if n is divisible by i, then n is not prime
// change flag to 1 for non-prime number
if (n % i == 0) {
flag = 1;
break; } }
// flag is 0 for prime numbers
if (flag == 0)
printf("%d is a prime number.", n);
else
printf("%d is not a prime number.", n);
return 0; }
Control Flow Graph
Calculate the cyclomatic complexity by using the following formula −
• V(G) = e - n + 2*p
In the control flow diagram above,
where e = 10, n = 8, and p =1
As a result, V(G) = 10 - 8 + 2 * 1 = 4 Cyclomatic Complexity
BASIS PATHS
• A – B – F – G – H is the first path.