What is Branch coverage?
A white-box testing coverage criterion that requires both the true and false branches of every decision (such as an if statement) in a program to be executed at least once. It is also called decision coverage or C1, and it is stronger than statement coverage (C0), which requires every statement to be executed at least once.
Japanese name: 分岐網羅
Branch coverage appears in 2 practice questions across 1 topic, including Software Development and Project Management.
Field: Software Development and Project Management
Relation to condition coverage and compound conditions
When a decision is made of several conditions, as in 'A and B', condition coverage requires each individual condition to take both true and false. The two test cases (A = true, B = false) and (A = false, B = true) achieve condition coverage, but the decision is false in both, so branch coverage is not achieved. Therefore criteria such as decision/condition coverage, which satisfies both, and MC/DC (modified condition/decision coverage), which checks that each condition independently affects the outcome of the decision, are used. MC/DC is required at the highest safety level of DO-178C, the standard for airborne software, and is also highly recommended at ASIL D in ISO 26262, the functional safety standard for road vehicles.
FAQ
What do C0 and C1 mean?
They are abbreviations for coverage criteria: C0 is statement coverage (every statement executed at least once) and C1 is branch coverage (both the true and false sides of every branch executed at least once). Achieving C1 also achieves C0.
Should 100% branch coverage be the goal?
For safety-related software, standards or company rules may set targets for branch coverage or MC/DC. Otherwise, rather than insisting on 100%, it is important to check whether each unexecuted branch is really unnecessary or whether tests are missing. Code that runs only in abnormal situations needs to be tested, for example by fault injection.