You are on page 1of 4

Loop Testing:

Simple Loop:

i=1;

while (i<10)

cout<<”Hello World”;

i++;

Test Case Input Expected Output


TC1 i=10 Loop will not execute
TC2 i=9 Loop will execute only once
TC3 i=8 Loop will execute twice
TC4 i=5 Loop will execute 5 times
TC5 i=2 Loop will execute n-1 times
TC6 i=1 Loop will execute n times
TC7 i=0 Loop might execute 10 times
(n+1 times)
Where n is the total number of times that this loop will be executed.

Nested Loop:

for(int i=1 ; i<=5; i++){

for(int j=1; j<=5; j++){

cout<<”*****”<<endl;

Test Case Input Expected Output


TC1 I=1 ; j=6 Inner loop will not be executed
TC2 I=1 ; j=5 Inner loop will execute only once
TC3 I=1 ; j=4 Inner loop will execute twice
TC4 I=1 ; j=3 Inner loop will execute 3 times
TC5 I=1; j=2 Inner loop will execute 4 times
(n-1 times
TC6 I=1 ; j=1 Inner loop will execute 5 times (n
times )
TC7 I=1; j=0 Inner loop might execute 6 times
(n+1 times)
TC8 I=6 ; j=3 Outer loop will not execute
TC9 I=5 ; j=3 Outer loop will execute only
once
TC10 I=4 ; j=3 Outer loop will execute twice
TC11 I=3 ; j=3 Outer loop will execute 3 times
TC12 I=2 ; j=3 Outer loop will execute 4 times
(n-1 times)
TC13 I=1 ; j=3 Outer loop will execute 5 times
(n times)
TC14 I=0 ; j =3 Outer loop might execute 6 times
(n+1 times)
Where n is the total number of times the loop will execute.

Condition coverage:

Statement Coverage:

For 1 test case:

If (a>b) {

c=a-b;

This code can have only ne test case in which the value of a is less than b.

For 2 Test Cases:

Cout<<”Enter your choice;

Cin>>ch;

Switch(ch) {

Case 1: cout<<”hello world”:

Case 2: cout<<”Intro to SE”;

This case will execute completely when there are two test cases i.e. when the choice entered by user is 1
and in the next test case when the choice entered by the user is 2.
Decision coverage:

Get any number


from the user as 1
“num”

2
YES NO
Is the num even

C
B

even=num*2 3

D
End if

4
YES No
num < 50

F G

5 Print “The even number Print “The even number 6


is less than 50”” is greater than 50”

I H
End if
Read num;

If (num%2!=0)

even=num*2;

end if

if (num<50)

print “the even number is larger than 50”

end if

else

print “the even number is less than 50”

end else

Paths that ensure that all the edges are covered at least once:

1A-2C-3D-E-4G-6H

1A-2B-E-4F-5I

The Branch Coverage is 2.

You might also like