St
atementCov
erageTest
ing
Stat
ementcover
agei
soneoft
hewi
del
yusedsof
twar
etest
ing.I
tcomesunderwhi
te
boxtest
ing.
Statementcover
aget echni
queisusedtodesignwhi
teboxt
[Link]
stechni
que
i
nv olv
esexecuti
onofal lstat
ementsofthesourcecodeatl
[Link]
calculat
ethetotalnumberofexecut edst
atement
sinthesourcecodeoutoft otal
statementspr
esenti
nt hesourcecode.
Stat
ementcover
ageder i
vesscenar
iooftestcasesunderthewhit
eboxt
esti
ngprocess
whichi
sbasedupont hestr
uctur
eofthecode.
Inwhit
eboxtesting,concent
rat
ionofthet est
erisont heworki
ngofi
nter
nalsource
codeandfl
owchar torf
lowgraphofthecode.
Generall
y ,
intheinternalsourcecode,thereisawidevari
etyofelementsli
keoperators,
methods,ar rays,l
oopi ng,contr
olstat
ement s,except
ionhandlers,et
[Link] he
i
nputgi ventot heprogr am,somecodest atementsareexecut
edandsomemaynotbe
[Link] goalofst atementcov erage t
echni
que i
st o coverallthe possibl
e
executi
ngst atementsandpat hl
inesi
nt hecode.
Let
'sunder
standt
hepr
ocessofcal
cul
ati
ngst
atementcov
eragebyanexampl
e:
Here,wearetakingsourcecodetocreat
etwodiffer
entscenar
iosaccordi
ngt
oinput
val
uestocheckthepercent
ageofst
atementcov
erageforeachscenar
io.
Sour
ceCodeSt
ruct
ure:
o Takei
nputoft
wov
aluesl
i
kea=0andb=1.
o Fi
ndt
hesum oft
heset
wov
alues.
o I
fthesum i
sgr
eat
ert
han0,
thenpr
int"
Thi
sist
heposi
ti
ver
esul
t.
"
o I
fthesum i
slesst
han0,
thenpr
int"
Thi
sist
henegat
iver
esul
t.
"
[Link]
(int
a,
i
nt
b)
2.{
[Link] ion
to pri
nt
sum of
these
int
eger
val
ues
(sum
= a+b)
[Link] (
sum>0)
5.{
[Link] i
nt (
This i
s posi
tive r
esult)
7.} else
8.{
[Link] i
nt (
This i
s negati
v e
resul
t)
10.
}
11.
}
So,
thi
sist
hebasi
cst
ruct
ureoft
hepr
ogr
am,
andt
hati
sthet
aski
tisgoi
ngt
odo.
Now,let
's see the t
wo dif
fer
entscenar
ios and cal
cul
ati
on oft
he per
cent
age of
St
atementCoverageforgi
vensour
cecode.
Scenar
io1:
I
fa=5, b=4
[Link]
nt (
int
a,
int
b)
{
2.i
nt sum = a+b;
3.i
f (
sum>0)
[Link]
nt (
"This
is
a posi
ti
ve r
esult
")
[Link]
se
[Link]
nt (
"This
is
negati
ve r
esult
")
7.}
Inscenari
o1, wecanseetheval
ueofsum wil
lbe9t
hati
sgr
eat
ert
han0andaspert
he
condit
ionresul
twil
lbe"Thi
sisaposi
ti
veresul
t."
To cal
cul
ate st
atementcover
age ofthe f
ir
stscenari
o,take t
he t
otalnumberof
st
atement
sthatis7andthenumberofusedst
atement
sthatis5.
[Link]
al
number
of st
atements
= 7
[Link]
of
executed
stat
ement s
= 5
[Link]
atement
cov
erage
= 5/
7*100
2.=
500/7
3.=
71%
Li
kewi
se,
inscenar
io2,
Scenar
io2:
I
fA=- 2,B=-7
[Link]
int
(
int
a,
int
b)
{
2.i
nt
sum = a+b;
3.i
f (
sum>0)
[Link]
nt
("
Thi
s i
s a
posit
ive r
esult
")
[Link]
se
[Link]
nt
("
Thi
s i
s negat
ive r
esult
")
7.}
Inscenari
o2,wecanseetheval
ueofsum wil
lbe-9t
hati
slesst
han0andaspert
he
condi
tion,
resul
twi
l
lbe"Thi
sisanegat
iver
esul
t."
To cal
cul
ate st
atementcover
age ofthe f
ir
stscenar
io,t
ake t
he t
otalnumberof
st
atement
sthatis7andthenumberof
usedstat
ementst
hati
s6.
Tot
alnumberofstat
ements=7
Numberofexecut
edstat
ement
s=6
[Link]
atement
cov
erage
= 6/
7*100
<br
>
2.=
600/7
3.=
85%
But,wecanseeallthest
atement
sarecoveredi
nbot
hscenar
ioandwecanconsi
der
thatt
heover
all
stat
ementcover
ageis100%.
So,
thest
atementcov
eraget
echni
quecov
ersdeadcode,
unusedcode,
andbr
anches.
Br
anchCov
erageTest
ing
Branchcoveragetechni
queisusedt ocoverallbr
anchesofthecontr
olfl
ow [Link]
coversal
lthepossibl
eoutcomes( tr
ueandfal
se)ofeachcondit
ionofdeci
sionpointat
l
[Link]
aget echni
queisawhit
eboxtesti
ngt
echniquet
hatensuresthat
everybr
anchofeachdecisionpointmustbeexecut
ed.
Howev er
,branchcov
eragetechni
queanddecisi
oncover
agetechni
quear everysimil
ar,
butthereisakeydiff
erencebetweenthet
[Link]
oncoveragetechniquecoversall
branchesofeachdecisi
onpointwhereasbrancht
esti
ngcoversal
lbr anchesofev er
y
deci
sionpoi
ntoft
hecode.
Li
kedecisi
oncov
erage,i
tal
sousesacont
rolf
low gr
apht
ocal
cul
atet
henumberof
br
anches.
Howt
ocal
cul
ateBr
anchcov
erage?
Ther
earesever
almet
hodst
ocal
cul
ateBr
anchcov
erage,butpat
hfi
ndi
ngi
sthemost
commonmethod.
Inthismethod,t henumberofpathsofexecut edbranchesisusedt ocalculat
eBr anch
[Link] anch cov
erage t
echnique can be used as the al
ternat
ive ofdeci sion
[Link] e,i
tisnotdef
inedasani ndiv
idualtechni
que,butiti
sdi st
inctfrom
decisi
oncov erageandessenti
alt
otestallbr
anchesoft hecontrol
flowgraph.
Let
'sunder
standi
twi
thanexampl
e:
[Link] X
[Link] Y
3.I
F X+Y >
100 THEN
[Link]
nt
"Large"
[Link]
6.I
f
X + Y<100 THEN
[Link]
nt
"Smal l
"
[Link]
Thisist hebasiccode struct
urewhere we t
ookt wo var
iablesX and Y and t
wo
condit
[Link]
hefir
stcondi
ti
onistr
ue,
thenpri
nt"Lar
ge"andifitisf
alse,
thengotothe
nextconditi
on.I
fthesecondcondi
ti
oni
strue,
thenpri
nt"Smal
l."
Cont
rol
flowgr
aphofcodest
ruct
ure
I
nt heabov ediagram,contr
olflowgraphofcodei sdepi
ct [Link]
rstcasetraver
sing
thr
ough" Yes"decisi
on,thepathis
A1-B2-C4-D6-E8,
andt henumberofcov er
ededgesi s
1,2,4,5,6and8butedges3and7ar enotcov eredinthispat [Link],
wehav etot r
aversethr
ough" No"deci
[Link]" No"decisi
onthepat hisA1-B3
-5-
D7,andt henumberofcov erededgesi [Link] raveli
ngthroughthesetwo
paths,
allbrancheshav ecovered.
Path1-A1-B2-
C4-D6-
E8
Path2-A1-B3-
5-D7
BranchCov
erage(BC)=Numberofpat
hs=2
Case Cov
eredBr
anches Pat
h Branch
coverage
Yes 1,
2,4,
5,6,
8 A1-
B2-
C4-
D6-
E8 2
No 3,
7 A1-
B3-
5-D7
Condi
ti
onCov
erageTest
ing
Conditi
oncov erageisal soknownasPr edi
cateCov erageinwhicheachoneoft he
Booleanexpr essionhav ebeenev [Link] smeanst hat
each indi
v i
dualcondi t
ion isonet imet rueand f al
se.I notherwordswecov eral
l
condit
ions,hence condi t
ion [Link] out come oft he deci
sion pointi
s onl
y
rel
evantf orchecki ng thecondi t
[Link] so t
hecombi nati
onsofconditionsarenot
rel
[Link] her
ear eonlyt wopossi bl
eoutcomesofacondi t
ion(trueorfal
se),
condit
ioncov erageresultsin2testsi t
uati
onsperdecisionpoint.
Deci
sionCov
erageTest
ing
Decisi
oncov eraget echniquecomesunderwhi teboxt est
ingwhi chgivesdecision
coveragetoBooleanv [Link]
stechniquerepor
tstrueandfalseoutcomesofBoolean
expressi
[Link] ert her
ei s a possi
bil
it
yoft wo ormor e outcomes fr
om t he
stat
ement sli
kedowhi l
est at
ement,ifstatementandcasest atement( Cont
rolfl
ow
stat
ement s)
,itisconsideredasdecisionpointbecausetherearet wooutcomeseither
tr
ueorf al
se.
Decisi
oncover
agecov
ersallpossibl
eoutcomesofeachandev
eryBool
eancondi
ti
onof
thecodebyusi
ngcont
rolf
lowgr aphorchart
.
Gener al
ly
,adecisi
onpoi
nthast wodeci si
onv al
uesoneistrue,andanotheri
sf al
se
that'
swhymostoft heti
mest het ot
alnumberofout comesi [Link]
decisioncover
agecanbefoundbydi vi
dingthenumberofexerci
sedoutcomewiththe
totalnumberofout
comesandmul t
ipli
edby100.
Inthi
st echni
que, i
tistought oget100%cov eragebecausesomet i
mesexpressi
onsget
compl i
[Link] t ot his,ther
e are severaldif
fer
entmet hods toreportdeci
sion
[Link] hodscoverthemosti mport
antcombi nat
ionsandv er
ymuch
simil
art odecisioncov [Link] i
toft hesemet hodsisenhancementoft he
sensi
tivit
yofcont r
olfl
ow.
Wecanf
indt
henumberofdeci
sioncov
erageasf
oll
ows.
Let
'sunder
standi
tbyanexampl
e.
Consi
dert
hecodet
oappl
yondeci
sioncov
eraget
echni
que:
[Link]
(i
nt a)
2.{
[Link]
(a>4)
4.a=a*3
[Link]
nt (
a)
6.}
Scenari
o1:
Valueofai
s7(
a=7)
[Link]
(i
nt
a=7)
2.{
if
(
a>4)
3.a=a*3
[Link]
nt
(a)
5.}
Thecodehi
ghli
ghtedinyel
lowi
sexecut
[Link]
comeoft
hiscodei
s"Tr
ue"i
f
condi
ti
on(
a>4)ischecked.
Cont
rol
flowgr
aphwhent
hev
alueofai
s7.
Cal
cul
ati
onofDeci
sionCov
erageper
cent
:
Deci
sion
Cov
erage
= ½*
100
(
Onl
y
"Tr
ue"
i
s exer
cised)
=100/
2
= 50
Deci
sion
Cov
erage
i
s 50%
Scenari
o2:
Valueofais3(
a=3)
[Link]
(i
nt
a=3)
2.{
if
(
a>4)
3.a=a*3
[Link]
nt
(a)
5.}
Thecodehi
ghl
ightedinyel
lowwi
l
lbeexecut
[Link]
comeoft
hiscodei
s?Fal
se?i
f
condi
ti
on(
a>4)ischecked.
Cont
rol
flowgr
aphwhent
hev
alueofai
s3
Cal
cul
ati
onofDeci
sionCov
erageper
cent
:
1.=
½* 100
(Onl
y
"Fal
se"
is
exer
cised)
<br
>
2.=100/2
3.=
50
[Link]
on Cover
age
= 50%
Resul
ttabl
eofDeci
sionCov
erage:
TestCaseVal
ueofAOutput
Deci
sionCov
erage
1 3 3 50%
2 7 21 50%
MULTI
PLECONDI
TIONCOVERAGE
I
trepor
ts aboutwhet
herev
ery possi
ble combi
nat
ion of
Bool
eansubexpr
essi
onsoccur
s.
Testcasesr
equi
redar
egi
venbyt
hel
ogi
caloper
atort
rut
h
t
abl
efort
hecondi
ti
on.
Thi
srequi
ref
ourt
estcasesf
oreachoft
hecombi
nat
ionsof
aandbf
orbot
htr
ueandf
alse.
I
tismor
edet
ail
edf
orm.
I
trequi
res t
hat al
ltr
ue-
fal
se combi
nat
ion of si
mpl
e
condi
ti
onsbeexer
cisedat
leastonce.
Ther
e ar
e atmost2^
ntr
ue f
alse combi
nat
ions f
ora
compoundpr
edi
cat
ewi
thnsi
mpl
econdi
ti
ons.
Mul
ti
ple condi
ti
on cov
erage ensur
es t
hatal
lst
atement
br
anchesandcondi
ti
onsar
ecov
eredbutnotal
lpat
hs.
Reachi
ngal
lcondi
ti
onscombi
nat
ionsmaybei
mpossi
ble.
Thi
smayal
sopr
ecl
udecer
tai
ncombi
nat
ions.