Lecture 41: White Box Testing - Path & Condition Coverage
Unit 5: Software Coding and Testing (4353202)
Lecture Agenda
- Recap of Statement & Branch Coverage
- What is Path Coverage?
- What is Condition Coverage?
- Advantages of Path & Condition Coverage
- Disadvantages of Path & Condition Coverage
- Key Takeaways
Recap of Statement & Branch Coverage
- Statement Coverage: Ensures every executable line of code is executed.
- Branch Coverage: Ensures every decision path (true/false) is exercised.
- Branch coverage is a stronger form of testing than statement coverage.
What is Path Coverage?
Path Coverage ensures that every possible independent path through the code is executed at least once. An independent path is a path through the code that introduces at least one new set of processing statements or a new condition.
This is the most comprehensive form of code coverage, but also the most difficult to achieve, especially for complex programs.
public void example(int a, int b) {
if (a > 0) { // Path 1
if (b > 0) { // Path 2
System.out.println("Both positive"); // Path 3
} else {
System.out.println("A positive, B non-positive"); // Path 4
}
} else {
System.out.println("A non-positive"); // Path 5
}
}Possible Paths:
- a > 0, b > 0
- a > 0, b <= 0
- a <= 0
What is Condition Coverage?
Condition Coverage ensures that every boolean sub-expression (condition) within a decision statement has been evaluated to both true and false at least once.
This is particularly useful for complex conditional statements involving logical operators (AND, OR, NOT).
public void checkDiscount(int age, boolean isMember) {
if (age >= 65 && isMember) { // Condition: (age >= 65) AND (isMember)
System.out.println("Senior Member Discount");
} else {
System.out.println("No Discount");
}
}Conditions to test:
- `age >= 65` (True and False)
- `isMember` (True and False)
Advantages of Path & Condition Coverage
- High Thoroughness: Path coverage provides the most comprehensive testing of code logic.
- Reveals Hidden Bugs: Condition coverage can uncover bugs in complex logical expressions that might be missed by branch coverage.
- Improved Code Quality: Encourages developers to write cleaner, more testable code.
- Reduced Risk: Minimizes the risk of untested code paths or logical errors in critical conditions.
Disadvantages of Path & Condition Coverage
- High Complexity: The number of paths can grow exponentially with decision points, making 100% path coverage impractical for large programs.
- Time-Consuming: Requires significant effort to identify and create test cases for all paths and conditions.
- Not Always Feasible: Some paths or conditions might be unreachable or logically impossible to test.
- Doesn't Guarantee Correctness: Even 100% coverage doesn't guarantee the absence of all bugs (e.g., missing functionality).
Key Takeaways
- **Path Coverage** tests every independent path through the code, offering the highest level of thoroughness.
- **Condition Coverage** ensures every boolean sub-expression evaluates to both true and false.
- These are advanced white box techniques that provide **deeper insight into code logic** but come with **higher complexity and effort**.
Next Lecture
Topic: Test Case Templates & Design
Q & A
Questions & Discussion

