Testing with full knowledge of internal code structure, logic, and implementation. The 'box' is transparent.
White-box testing is performed by developers and advanced QA engineers who understand code. The goal is to test internal logic, verify all code paths are executed, find dead code, optimize performance, and catch security vulnerabilities at the code level. It's the deepest level of testing.
Like disassembling a microwave to check circuit design, component quality, signal flow, and whether all parts are working correctly - not just checking if food heats up.
| Name | Description | Example |
|---|---|---|
| Line Coverage | Percentage of code lines executed by tests | If code has 100 lines and tests execute 80, coverage = 80% |
| Branch Coverage | Percentage of if/else branches taken | If statement has 2 branches (if true, if false). Both must be tested for 100% branch coverage |
| Path Coverage | All possible execution paths through code | Code has 3 if-statements. Total paths = 2³ = 8. Must test all 8 combinations. |
| Function Coverage | All functions/methods are called at least once | Code has 50 functions. All 50 must be invoked during testing. |
Testing discount calculation function
function calculateDiscount(price, discount) { if (discount > 50) { discount = 50; } return price - (price * discount / 100); }
You test internal logic: the if-statement checking if discount > 50. You know it's there because you can see the code.
Testing login validation logic
if (email.contains('@') && password.length >= 8) { login(); } else { showError(); }
You know the exact conditions (contains '@' AND length >= 8). You test each branch.
You're reviewing a discount calculation function: if (customerType == 'VIP') discount = 20%; else if (customerType == 'Regular') discount = 10%; else discount = 0%; What white-box test cases would you write to achieve 100% coverage?
🔍 White-box: Developer perspective, full code access. Test internal logic, branches, and edge cases.
Developers are expected to do white-box testing. QA should understand the concept and work with developers.