Quiz 2
Registry Synced

⬜ White-Box Testing

232 words
1 min read

Reading compass

Now · 1. 🎯 Learning Objectives

⬜ 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 TypeDefinitionFormula
StatementEvery statement executedExecuted / Total statements
BranchEvery decision outcome takenOutcomes taken / Total outcomes
PathEvery possible path through codePaths tested / Total paths
ConditionEvery boolean sub-expression evaluated to T/FConditions tested / Total

3.2 Cyclomatic Complexity

Measure of program complexity = number of independent paths. Formula: M=EN+2PM = E - N + 2P (edges - nodes + 2 × connected components) Simpler: M=decision points+1M = \text{decision points} + 1 (for single-function)
java
public 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 2N2^N 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
Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.