Code Coverage

What does coverage actually mean? There are different categories.

Statement Coverage

Statement coverage is achieved when all statements in a method have been executed at least once.

Faults cannot be discovered if the parts containing them are not executed Equivalent to covering all nodes in control flow graph (actual % of coverage would be different) Executing a statement is a weak guarantee of correctness, but easy to achieve In general, several inputs execute the same statements – important question in practice is how can we minimize test cases?

  • Statement coverage is most used in industry
  • Typical coverage target is 80-90% (not 100% because there is dead code, and no need to test on getter and setter methods)

Branch Coverage

Branch coverage is achieved when every branch from a node is executed at least once

  • At least one true and one false evaluation for each predicate
  • Can be achieved with D+1 paths in a control flow graph with D 2-way branching nodes and no loops
    • Even less if there are loops

Condition Coverage

Condition coverage reports the true or false outcome of each condition. Condition coverage measures the conditions independently of each other.