What will be the statement coverage, decision coverage and branch coverage of these following problem?

I have been trying to get ISTQB certification and this is my first time with manual testing stuffs, I found it very interesting but can some please tell me how to find the statement coverage, decision coverage and branch coverage for the following pseudo code: I tried a little long but still I cannot identify the concept . Please help me to clarify the logic behind this calculation. The Pseudo code are:

PSEUDO code 1:

`````` Read A
if A>0 then
if B>0 then
print "No Valid"
else
print "B"
if A = 21 then
print A
End if
End if
End if
``````

PSEUDO code 2:

`````` Read A
if A > 0 THEN
if A = 12 THEN
Print "Hey"
End if
End if
``````

What will be the statement coverage, decision coverage and branch coverage for these PSEUDO CODES? And please help me with the logic of calculating it

• you are looking for inputs to validate all these coverages ? what is the actual output or answer you expects Commented Feb 22, 2021 at 12:47
• @PDHide The output, rather the purpose of this question is to understand the concepts of Statement coverage and Decision or Branch coverage. Commented Feb 24, 2021 at 10:40
• Unless the author confirms what they expect , do the author expects someone to answer what inputs give 100% of each of this coverage Commented Feb 24, 2021 at 10:44

Statement coverage means every statement had to be executed. Decision coverage measures the coverage of conditional branches. Branch coverage measures the coverage of conditional and unconditional branches. At 100 %, they give the same result. You can see a discussion on differences between these two here.

1/

``````Read A
if A>0 then
if B>0 then
print "No Valid"
else
print "B"
if A = 21 then
print A
End if
End if
End if
``````

Statement coverage could be achieved with one input value:

``````A=1, B=1
A=21, B=0
``````

Decision coverage and branch coverage could be achieved with these input values:

``````A=0, B=0
A=21, B=0
A=20, B=0
A=21, B=1
``````

2/

I added "if" on the 3rd line since I believe it was missing. I also added spaces so it's a bit more readable.

``````Read A
if A > 0 THEN
if A = 12 THEN
Print "Hey"
End if
End if
``````

Statement coverage could be achieved with one input value: `A=12`. Decision coverage and branch coverage could be achieved with these input values:

``````A=12
A=13 (or any other value greater than 0 and not equal to 12)
A=0 (or any other value less than or equal to 0)
``````

Note that some of the values are just random values that will fit in in order to cause some decision to true or false, but my choice of values is not the only correct one, you can choose different values and achieve the same result.

Edit: PDHide mentioned decision coverage and branch coverage are not the same, which is true. I updated my post slightly to better explain it, plus I deleted the link to an article that might have mentioned these two coverages are the same. I didn't change the values since if you want to achieve 100 % branch or decision coverage, you can use the same values here.

If you are concerned about the number of test cases that you need in order to achieve 100 % branch and decision coverage, than this can differ in some situations like:

``````function test(a, b):
return a > 0 and b < 10
``````

In this example, there's one decision and no branch. Therefore, you need two test cases to achieve 100 % decision coverage, but one test case to achieve 100 % branch coverage.

To illustrate than is means by conditional and unconditional branches, let's consider this example:

``````if A = 12 THEN
Print A
End if
Print 0
``````

Here, there're two conditional branches and one unconditional branch:

• Thanks for the explanation. So for first question statement coverage will be 2 and decision coverage will be 4 , and for 2 nd question statement coverage will be 1 and decision coverage will be 3? Commented Feb 23, 2021 at 0:27
• Yes, you can achieve the coverages with these numbers. Commented Feb 23, 2021 at 7:44
• branch coverage and condition coverage are not the same Commented Feb 23, 2021 at 17:03
• I updated my post to better explain it, thank you @PDHide Commented Feb 24, 2021 at 12:42