Skip to main content

Black-box versus white-box testing

Short answer

The fundamental difference is that black-box testing derives tests from the specification without seeing code, while white-box testing uses internal code structure to exercise statements, branches, and paths. Black-box finds missing functions and interface errors; white-box finds logic errors and unreachable code. Both are complementary.

What is the fundamental difference between a black-box test and white-box test? Explain with appropriate examples of software test.

The fundamental difference is what the tester can see. In black-box testing the program is treated as a closed box: test cases are derived only from the specification (inputs and expected outputs), without looking at the code. In white-box testing (glass-box or structural testing) test cases are derived from the internal structure of the code, so that statements, branches and paths are exercised.

PointBlack-box testingWhite-box testing
Basis of testsRequirements/specificationSource code and logic
Knowledge of codeNot neededRequired
Also calledFunctional, behavioural testingStructural, glass-box testing
TechniquesEquivalence partitioning, boundary value analysis, decision tablesStatement, branch, path coverage, basis path testing
FindsMissing/incorrect functions, interface and performance errorsLogic errors, unreachable code, wrong conditions
LevelMostly system and acceptance testingMostly unit testing
Done byIndependent testers, usersDevelopers

Example of a black-box test

A form accepts age from 18 to 60. Without reading the code, the tester chooses equivalence classes and boundaries:

InputClassExpected
17below rangeRejected
18lower boundaryAccepted
35validAccepted
60upper boundaryAccepted
61above rangeRejected

Example of a white-box test

int grade(int marks) {
    if (marks >= 40)
        return PASS;
    else
        return FAIL;
}

The tester reads the code and sees one decision, so cyclomatic complexity V(G) = 1 + 1 = 2. Two test cases give full branch coverage: marks = 40 (true branch, PASS) and marks = 39 (false branch, FAIL).

Black-box testing cannot show that every part of the code was executed, and white-box testing cannot show that a required function is missing. So both are used together.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Software Engineering chapter 8 questions →