⬜ White-Box Testing
232 words
1 min read
Visual companion
Python
Type and operator map
Python Week 1: the first filter for runtime behavior
View
Revision summary
What this note is really saying
Short form
# ⬜ White-Box Testing ## 1. 🎯 Learning Objectives - Calculate statement, branch, and path coverage - Compute cyclomatic complexity - Design test cases from code structure ## 2.

⬜ White-Box Testing
1. 🎯 Learning Objectives
- Calculate statement, branch, and path coverage
- Compute cyclomatic complexity
- Design test cases from code structure
2. 📖 Core Content
3.1 Coverage Types
| Coverage Type | Definition | Formula |
|---|---|---|
| Statement | Every statement executed | Executed / Total statements |
| Branch | Every decision outcome taken | Outcomes taken / Total outcomes |
| Path | Every possible path through code | Paths tested / Total paths |
| Condition | Every boolean sub-expression evaluated to T/F | Conditions tested / Total |
3.2 Cyclomatic Complexity
Measure of program complexity = number of independent paths.
Formula: M=E−N+2P (edges - nodes + 2 × connected components)
Simpler: M=decision points+1 (for single-function)
javapublic void process(int x) { // 1 if (x > 0) { // decision = 1 System.out.println("+"); } else { // implicit else System.out.println("-"); } System.out.println("done"); // end }
Decision points: 1 (if). M = 1 + 1 = 2 (2 independent paths).
3.3 Path Testing
For a function with N conditions, there are 2N possible paths. Exhaustive path testing is impossible for large N — use branch/decision coverage instead.
4. 📝 Practice Questions
Q1: Function with 3 if-else statements. What is the cyclomatic complexity?Answer: M = 3 + 1 = 4. There are 4 independent paths through the function. (Or M = E - N + 2P for a more precise calculation.) Join Discord PreviousBlack-Box TestingNextTDD & Mutation Testing