When using logical operators like && or ||, the compiler generates multiple branches to support short-circuiting. To reach 100% coverage, you must provide test cases that exercise every possible evaluation path.
For if (a && b)
This pattern typically reports 4 branches. To cover them, you need at least three distinct test cases:
a=true, b=true (Executes the then block)a=true, b=false (Short-circuits on b)a=false (Short-circuits on a; b is not evaluated)
For if (a || b)
This pattern also typically reports 4 branches. To cover them, you need:
a=false, b=false (Both evaluated, result false)a=false, b=true (Short-circuits on b)a=true (Short-circuits on a; b is not evaluated)
For Compound Conditions (e.g., if (a && b && c))
Each additional logical operator increases the branch count. For three conditions, you need cases that fail at each step (e.g., a is false, then b is false, then c is false) plus a case where all are true.
[Fact]
public void Test_AllBranches()
{
Example(true, true); // a=true, b=true → executes block
Example(true, false); // a=true, b=false → skips block
Example(false, true); // a=false → skips block (b not evaluated)
Example(false, false); // a=false → skips block (b not evaluated)
}