Certopolis

ISTQB Certified Tester Foundation Level

Statement coverage vs branch coverage for ISTQB CTFL

Statement coverage is the executable statements exercised divided by all executable statements. Branch coverage is the branches exercised divided by all branches, where a branch is control passing from one node of the control flow graph to another. ISTQB's CTFL v4.0 syllabus states that 100% branch coverage always gives 100% statement coverage, but not the reverse.

How is statement coverage measured, and what does it miss?

The coverage items are executable statements. With 100% statement coverage, every executable statement has run at least once, so every statement containing a defect has been executed.

Running a defective statement does not always reveal the defect. Some defects depend on the data, such as a division that fails only when the denominator is zero. Full statement coverage also leaves open whether the decision logic was fully tested, because it may leave branches unexercised.

Example: line 1 fee = 5, line 2 if weight > 20 then, line 3 fee = fee + 3, line 4 end if, line 5 total = price + fee. One test with weight = 25 runs every statement, so statement coverage is 100%. The false outcome of the decision on line 2 is never exercised.

How is branch coverage measured, and what does it miss?

A branch is either unconditional (straight-line code) or conditional (a decision outcome). Both kinds count. Conditional branches typically come from the true or false outcome of an if...then decision, from an outcome of a switch/case statement, or from the decision to exit or continue a loop.

In the example above, a second test with weight = 10 exercises the false outcome and brings branch coverage to 100%. Branch coverage subsumes statement coverage: any set of tests that reaches 100% branch coverage also reaches 100% statement coverage.

Branch coverage has its own gap. It may not detect defects that need a specific path through the code. Two tests can exercise every branch of two consecutive decisions without ever taking the path where both decisions are true.

What is the value of white-box testing?

Its strength is that the whole implementation is taken into account, which helps find defects even when the specification is vague, outdated or incomplete. Its weakness is the mirror image: if the software does not implement a requirement at all, white-box testing may not detect that omission.

White-box techniques can also be used in static testing, for example in dry runs of code, and suit code not yet ready to execute, pseudocode and other logic that can be modelled as a control flow graph.

Black-box testing alone does not tell you how much of the code was covered. Coverage measured with white-box techniques is objective and shows where further tests can be added to raise coverage and confidence in the code.

Where the exam catches people

  • Believing 100% statement coverage means every decision outcome was tested: an if without an else can be fully covered by statements with the false outcome never taken.
  • Believing the subsumption runs both ways: 100% branch coverage gives 100% statement coverage, not the reverse.
  • Counting only decision outcomes as branches: unconditional branches are coverage items as well.
  • Believing 100% branch coverage exercises every path: a defect that needs one particular path can survive it.
  • Believing white-box testing finds missing functionality: it works from the code that exists, so a requirement that was never implemented may go unnoticed.

Written from these sources

Try 3 questions on this

Pick an answer to see why each option is right or wrong.

  1. A pricing function: 1 discount = 0 2 if member = true then 3 discount = 10 4 end if 5 price = price - discount One test is run with member = true and price = 50. Which of the following statements about this test is CORRECT? Select ONE option.

    Right. In the game that’s Renown for your Test Analysis and Design building.

    Not that one: A is right. In the game your Test Analysis and Design building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    So the decision logic is not fully tested.

    Written from istqb.org/wp-content/uploads/2024/11/ISTQB_CTFL_Syllabus_v4.0.1.pdf

  2. A team's exit criteria for a component include 100% statement coverage. The test report shows 100% branch coverage for the component but contains no statement coverage figure. Which of the following can the team conclude? Select ONE option.

    Right. In the game that’s Renown for your Test Analysis and Design building.

    Not that one: A is right. In the game your Test Analysis and Design building would lose a little Renown, and this question would come back later.

  3. The requirement says a customer may use a coupon or a member discount, but never both on one order. The code is: 1 total = price 2 if coupon = true then 3 total = total - 10 4 end if 5 if member = true then 6 total = total * 0.9 7 end if Two tests pass: (coupon = true, member = false) and (coupon = false, member = true). In production, an order with both gets both discounts. Which of the following BEST explains why the tests missed this? Select ONE option.

    Right. In the game that’s Renown for your Test Analysis and Design building.

    Not that one: C is right. In the game your Test Analysis and Design building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    The failure only appears on the one path where both decisions are true, which neither test follows. Exercising every branch does not mean every path has been run.

    Written from istqb.org/wp-content/uploads/2024/11/ISTQB_CTFL_Syllabus_v4.0.1.pdf

Ask for something