White Box Testing Techniques

White Box Testing Techniques

White Box Testing Techniques

Understanding structural testing methods that examine the internal logic and code structure of software

S

Statement Coverage

Ensures every executable statement in the code is executed at least once.

Basic coverage criterion | Easy to achieve

B

Branch Coverage

Ensures each decision point (branch) in the code is taken in all possible directions.

Stronger than statement coverage | Tests all outcomes

C

Condition Coverage

Ensures each boolean sub-expression evaluates to both true and false.

Tests individual conditions | More thorough than branch coverage

MC

Multiple Condition Coverage

Tests all possible combinations of conditions in a decision.

Most comprehensive | Can generate many test cases

BP

Basis Path Testing

Tests all linearly independent paths through a program's control flow.

Uses cyclomatic complexity | Systematic approach

CC

Cyclomatic Complexity

Quantitative measure of the number of linearly independent paths through code.

Metric for complexity | Guides testing effort

L

Loop Testing

Focuses on validating the correctness of loop constructs.

Tests loop boundaries | Specialized technique

Statement Coverage

Basic Coverage

What is Statement Coverage?

Statement coverage is a white box testing technique that aims to execute every executable statement in the source code at least once. It's the most basic form of code coverage.

How it Works

The goal is to create test cases that ensure no statement in the code is left unexecuted. This technique helps identify:

  • Dead code (code that cannot be reached)
  • Missing statements
  • Basic functionality issues

Limitations

While statement coverage is easy to achieve, it doesn't guarantee thorough testing because:

  • It doesn't test all decision outcomes
  • It may miss errors in conditional logic
  • It doesn't verify the correctness of the statements

Code Example

function calculateGrade(score) {
  let grade;
  if (score >= 90) {
    grade = 'A'; // Statement 1
  } else if (score >= 80) {
    grade = 'B'; // Statement 2
  } else {
    grade = 'C'; // Statement 3
  }
  return grade; // Statement 4
}

Coverage Visualization

To achieve 100% statement coverage, we need test cases that execute all statements:

Statement 1: score=95
Statement 2: score=85
Statement 3: score=75
Statement 4: all cases

✅ 100% Statement Coverage Achieved

Branch Coverage

Decision Coverage

What is Branch Coverage?

Branch coverage (also called decision coverage) ensures that each decision point in the code (like if statements) takes both true and false paths at least once.

How it Works

This technique requires test cases that cause each branch direction to be executed. It's stronger than statement coverage because it verifies the decision logic.

Advantages Over Statement Coverage

  • Tests both outcomes of decisions
  • Helps find errors in conditional logic
  • Provides better code exercise than statement coverage

Example

For an if-else statement, branch coverage requires:

  • One test where the condition is true
  • One test where the condition is false

Code Example

function isEligible(age, hasLicense) {
  if (age >= 18) { // Branch 1
    if (hasLicense) { // Branch 2
      return true;
    } else {
      return false;
    }
  } else {
    return false;
  }
}

Branch Coverage Requirements

Age >= 18?
Has License?
Return True
Return False
Return False

Test cases needed for branch coverage:

  • age=20, hasLicense=true (True/True path)
  • age=20, hasLicense=false (True/False path)
  • age=16, hasLicense=any (False path)

Condition Coverage

Condition Testing

What is Condition Coverage?

Condition coverage ensures that each boolean sub-expression within a decision evaluates to both true and false.

How it Differs from Branch Coverage

While branch coverage tests the overall decision outcome, condition coverage tests each individual condition within compound decisions.

Example

For a condition like (A && B), condition coverage requires:

  • A true, B true
  • A true, B false
  • A false, B true
  • A false, B false

Code Example

if (temperature > 100 && pressure > 50) {
  shutdownSystem();
}

Condition Coverage Matrix

Test Case
Temperature > 100
Pressure > 50
Result
1
True
True
True
2
True
False
False
3
False
True
False
4
False
False
False

White Box Testing Techniques Explorer | Understanding structural testing methods

Comments

Popular posts from this blog

What is Software Testing? Complete Beginner-Friendly Guide

Defect Management: Complete Guide with Tools & Best Practices

SDLC Models: Complete Guide with Advantages & Disadvantages