Skip to main content
Course/Module 2/Topic 3 of 5Beginner

White Box Testing Techniques

Learn white box testing techniques that examine internal code structure and logic

50 minBy Priygop TeamLast updated: Feb 2026

White Box Testing Principles

  • Tests internal code structure and logic
  • Requires knowledge of source code
  • Focuses on code coverage
  • Tests all code paths and branches
  • Validates internal logic and algorithms

Code Coverage Types

Example
// Statement Coverage
// Every line of code is executed at least once
function calculateGrade(score) {
    if (score >= 90) {        // Line 1
        return 'A';           // Line 2
    } else if (score >= 80) { // Line 3
        return 'B';           // Line 4
    } else if (score >= 70) { // Line 5
        return 'C';           // Line 6
    } else {                  // Line 7
        return 'F';           // Line 8
    }
}

// Test cases for 100% statement coverage
test('score 95 should return A', () => {
    expect(calculateGrade(95)).toBe('A'); // Covers lines 1, 2
});

test('score 85 should return B', () => {
    expect(calculateGrade(85)).toBe('B'); // Covers lines 1, 3, 4
});

test('score 75 should return C', () => {
    expect(calculateGrade(75)).toBe('C'); // Covers lines 1, 3, 5, 6
});

test('score 65 should return F', () => {
    expect(calculateGrade(65)).toBe('F'); // Covers lines 1, 3, 5, 7, 8
});

// Branch Coverage
// Every decision point is tested for both true and false
function validateUser(user) {
    if (user.age >= 18) {           // Branch 1: true/false
        if (user.email) {           // Branch 2: true/false
            return true;
        }
    }
    return false;
}

// Test all branch combinations
test('valid adult with email', () => {
    const user = { age: 25, email: 'test@example.com' };
    expect(validateUser(user)).toBe(true); // Branch 1: true, Branch 2: true
});

test('valid adult without email', () => {
    const user = { age: 25, email: null };
    expect(validateUser(user)).toBe(false); // Branch 1: true, Branch 2: false
});

test('minor with email', () => {
    const user = { age: 17, email: 'test@example.com' };
    expect(validateUser(user)).toBe(false); // Branch 1: false
});
Chat on WhatsApp
Priygop - Leading Professional Development Platform | Expert Courses & Interview Prep