2
READ A
READ B
READ C
IF C>A THEN
IF C>B THEN
PRINT "C must be smaller bla bla.."
ELSE
PRINT "Proceed to next stage"
ENDIF
ELSE
PRINT "B CAN BE SMALLER THEN C"
ENDIF

Could someone explain to me the logic of calculating the number of statement and branch coverage (MINIMUM for both) for this task. I thought I understand these sort of tasks but this one got me stuck actually.

2

This becomes more readable with indentation:

READ A
READ B
READ C
IF C>A THEN
    IF C>B THEN
        PRINT "C must be smaller bla bla.."
    ELSE
        PRINT "Proceed to next stage"
    ENDIF
ELSE
    PRINT "B CAN BE SMALLER THEN C"
ENDIF

Statement coverage requires each statement to be executed, whereas branch coverage requires each branch (or decision) to be executed.

Usually, 100% branch coverage implies 100% statement coverage, but not necessarily vice versa. However, in this example both IFs have ELSE branches and, therefore, you have to execute all branches to reach each statement.

An example where statement coverage is not the same as branch coverage:

READ X
READ Y
IF X > Y
    X = X + 1
ENDIF
PRINT X

Here, statement coverage doesn't have to cover the case where X is smaller or equals Y—such that the line X = X + 1 isn't executed—which would be required with branch coverage.

If you are struggling with these questions, consider drawing a flow chart as shown, e.g., here: How to calculate Statement, Branch/Decision and Path Coverage for ISTQB Exam purpose

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.