STModule 2 Question Answers
STModule 2 Question Answers
Module 2
1 mark
2 marks
4 marks
To perform code coverage analysis various criteria are taken into consideration. These
are the major methods/criteria which are considered.
The number of statements that have been successfully executed in the program
source code.
Statement Coverage = (Number of statements executed)/(Total Number of
statements)*100.
The number of decision control structures that have been successfully executed in
the program source code.
3. Function coverage
The number of functions that are called and executed at least once in the source
code.
Function Coverage = (Number of functions called)/(Total number of
function)*100.
4. Condition Coverage/Expression Coverage
1. Source Lines of Code (SLOC) – It counts the number of lines in the source
code. It is the most straightforward metric used to measure the size of the
program. However, functionality and complexity do not relate that well as a
skilled developer might be able to deliver the same functionality with a
significantly smaller code.
For example, a module can be complicated, but only have a few interactions with
other modules. On the other hand, a module can be simple but highly coupled with
external modules. The higher the communication with external modules, the higher
the complexity of the codebase. Complexity metrics will look bad in the first case. In
the second case, the metrics will look good, but the code will be quite complex.
Therefore, it is crucial to measure the coupling and cohesion of modules. Only then
can we get an accurate system-level complexity measure.
15 marks
Example
Read X
Read Y
IF X+Y > 10 THEN
Print “Large”
ENDIF
If X > 50 THEN
Print “X Large”
ENDIF
For calculating Statement, Decision (Branch) and Path coverage, created a
flow chart for better understanding
Statement Coverage
Statement coverage is a white box testing technique where the all the
statements at the source code are executed at least once. To calculate
Statement Coverage, find out the shortest number of paths following which all
the nodes will be covered.
In the above example, in case of Yes, while traversing through each statement
of code and the traversing path (A1-B2-C4-5-D6-E8), all the nodes are
covered. So by traveling through only one path all the nodes (A, B, C, D and
E) are covered.
Statement coverage (SC) =1
Branch/Decision Coverage
Branch coverage covers both ways (true and false). It covers all the possible
outcomes of each condition at least once. Branch coverage is a white box testing
method that ensures that every possible branch from each decision point in the
code is executed at least once. To calculate Branch coverage, find out the
minimum number of paths which ensure covering of all the edges.
In the above example, in case of traversing through a Yes decision, path
(A1-B2-C4-5-D6-E8), maximum numbers of edges (1, 2, 4, 5, 6 and 8) are
covered but edges 3 and 7 are left out. To cover these edges, we have to follow
(A1-B3-5-D7). So by travelling through two paths (Yes, No), all the edges (1, 2, 3,
4, 5, 6, 7, 8) are covered.
Branch Coverage /Decision Coverage (BC) = 2
Path Coverage
It is executed in such a way that every path is executed at least once. It ensures
that every statement in the program is guaranteed to be executed at least one time.
Path Coverage ensures covering all the paths from beginning to end, in the above
example. All the possible paths are:
A1-B3-5-D7
A1-B2-C4-5-D6-E8
A1-B2-C4-5-D7
A1-B3-5-D6-E8
Path coverage (PC) = 4
Condition Coverage
It is related to decision coverage but has better sensitivity to the control flow.
Condition coverage reports the true or false outcome of each condition. It
measures the conditions independently of each other. Multiple condition coverage
is also known as condition combination coverage.
Let us take an example to explain condition coverage:
IF ("X && Y")
In order to suffice valid condition coverage for this pseudo-code, the following
tests will be sufficient.
TEST 1: X=TRUE, Y=FALSE
TEST 2: X=FALSE, Y=TRUE