You are on page 1of 8

COMSATS University Islamabad - Sahiwal Campus

Assignment No:3

Submitted By:
Mian Hasnain Ali

Reg# No.:
SP22-BSE-020

Submitted To:
Mam Mubeen Javed

Subject:
Software Engineering Concepts
Statement coverage
Statement Coverage is a white box testing technique in which all the executable
statements in the source code are executed at least once. It is used for calculation of the number of
statements in source code which have been executed. The main purpose of Statement Coverage is
to cover all the possible paths, lines, and statements in source code.

The formula to calculate Statement Coverage:

No. of Executed Statements


Statement Coverage =
Total Number of Statements

Example

Prints (int a, int b) ------- Print sum is a function


{
int result = a+ b;
If (result> 0)
Print ("Positive", result)
Else
Print ("Negative", result)
} ------- End of the source code

Scenario 1:

If a = 3, b = 9

prints (int a, int b)

int result = a+ b; 3

If (result> 0)

Print ("Positive", result)

Else
Print ("Negative", result)

1. The statements marked in navy blue color are those which are executed as per the
scenario
2. Number of executed statements = 5
3. Total number of statements = 7
4. Statement Coverage: 5/7 = 71%

Scenario 2:

If a = -3, b = -9

prints (int a, int b)

int result = a+ b; 3

If (result> 0)

Print ("Positive", result)

Else

Print ("Negative", result)

1. The statements marked in navy blue color are those which are executed as per the
scenario.
2. Number of executed statements = 6
3. Total number of statements = 7
4. Statement Coverage: 6/7 = 85%
Branch Coverage
Branch Coverage is a white box testing method in which every outcome from a
code module(statement or loop) is tested. The purpose of branch coverage is to ensure that each
decision condition from every branch is executed at least once. It helps to measure fractions of
independent code segments and to find out sections having no branches.
For example, if the outcomes are binary, you need to test both True and False outcomes.

The formula to calculate Branch Coverage:

No. of Executed Branches


Statement Coverage =
Total Number of Branches

Example

(int a)

If (a> 5)

a=a*3;

print(a)

}
Diagram

(int a) yes Conditional Branch


If (a> 5)

no
a=a*3;

print(a)
Unconditional Branch

Table

Test Case Value of A Output Decision Coverage Branch Coverage

1 2 2 50% 33%

2 6 18 50% 67%

Path Coverage
Path testing is a structural testing method that involves using the source code of a
program to find every possible executable path. It helps to determine all faults lying within a piece
of code. This method is designed to execute all or selected path through a computer program.
The formula to calculate Path Coverage:

No. of Executed Paths


Path Coverage =
Total Number of Path
Example

Read A

Read B

IF A+B > 50

THEN

Print "Large"

END IF

If A+B<50

THEN

Print "Small"

END IF
Diagram

Read A and B

2
Print Large

4
3

End If

6
Print Small

8
7

End If
Path Coverage ensures covering of all the paths from start to end.

All possible paths are:

1. 1-3-5-7
2. 1-3-5-6-8
3. 1-2-4-5-6-8
4. 1-2-4-5-7

So Path Coverage is 4.

You might also like