---
title: "Black-box versus white-box testing"
subject: "Software Engineering"
chapter: 8
key: "semester_5/software_engineering:black-box-vs-white-box"
source: https://www.bctengineer.com/q/semester_5/software_engineering/black-box-vs-white-box
site: BCT Engineering
---

# Black-box versus white-box testing

Software Engineering · Chapter 8: Software Testing and cost Estimation

- Asked in: 2069 Chaitra, 5 marks; year not given, 5 marks
- Video: [White Box vs Black Box Testing | Software Engineering](https://www.youtube.com/watch?v=89VOHd8F8Ao) — Gate Smashers
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_5/software_engineering/black-box-vs-white-box
- Whole chapter: https://www.bctengineer.com/md/semester_5/software_engineering/chapter-8

## Question

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

## 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.

## Answer

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.

| Point | Black-box testing | White-box testing |
|---|---|---|
| Basis of tests | Requirements/specification | Source code and logic |
| Knowledge of code | Not needed | Required |
| Also called | Functional, behavioural testing | Structural, glass-box testing |
| Techniques | Equivalence partitioning, boundary value analysis, decision tables | Statement, branch, path coverage, basis path testing |
| Finds | Missing/incorrect functions, interface and performance errors | Logic errors, unreachable code, wrong conditions |
| Level | Mostly system and acceptance testing | Mostly unit testing |
| Done by | Independent testers, users | Developers |

#### 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:

| Input | Class | Expected |
|---|---|---|
| 17 | below range | Rejected |
| 18 | lower boundary | Accepted |
| 35 | valid | Accepted |
| 60 | upper boundary | Accepted |
| 61 | above range | Rejected |

#### Example of a white-box test
```text
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.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What is the fundamental difference between black-box and white-box testing?
   A. Black-box tests run faster
   B. What the tester sees: specification only versus internal code structure
   C. Black-box tests need code knowledge
   D. White-box tests are only done by users
   Answer: B. Black-box derives tests from the specification without looking at code. White-box derives them from the internal structure. (Key point: Fundamental difference)

2. A form accepts age 18 to 60. Which set contains the boundary values for black-box testing?
   A. 17, 18, 60, 61
   B. 10, 30, 70
   C. 18, 35, 50
   D. 0, 100
   Answer: A. Boundary value analysis tests at and next to each edge: 17 and 18 at the lower edge, 60 and 61 at the upper edge. (Key point: Boundary values)

3. For grade(marks) with one if (marks >= 40), how many test cases give full branch coverage and why?
   A. 1, since there is one decision
   B. 2, one for each branch, e.g. 40 and 39
   C. 5, one per boundary
   D. 3, one per statement
   Answer: B. V(G) = 1 + 1 = 2. One test takes the true branch (40) and one the false branch (39). (Key point: White-box example)

## Related in Software Engineering

- [Black-box testing](https://www.bctengineer.com/question.md?key=semester_5%2Fsoftware_engineering%3Ablack-box-testing) — Software Engineering, chapter 8
- [Alpha versus beta testing](https://www.bctengineer.com/question.md?key=semester_5%2Fsoftware_engineering%3Aalpha-vs-beta) — Software Engineering, chapter 8
- [Software testing metrics](https://www.bctengineer.com/question.md?key=semester_5%2Fsoftware_engineering%3Atesting-metrics) — Software Engineering, chapter 8
- [Testing principles and testability](https://www.bctengineer.com/question.md?key=semester_5%2Fsoftware_engineering%3Atesting-principles) — Software Engineering, chapter 8
- [Functional versus structural testing; COCOMO for 200 KLOC](https://www.bctengineer.com/question.md?key=semester_5%2Fsoftware_engineering%3Afunctional-vs-structural-cocomo2) — Software Engineering, chapter 8
- [Real-time versus ordinary software and OS; data acquisition](https://www.bctengineer.com/question.md?key=semester_5%2Fsoftware_engineering%3Areal-time-vs-non-real-time) — Software Engineering, chapter 4

## Related in other subjects

- [White box and black box testing](https://www.bctengineer.com/question.md?key=semester_5%2Finstrumentation_ii%3Awhite-black-box) — Instrumentation II, chapter 9
- [Software bugs and testing techniques](https://www.bctengineer.com/question.md?key=semester_5%2Finstrumentation_ii%3Abug-types-testing) — Instrumentation II, chapter 9, asked 2×
- [Software testing time paradox](https://www.bctengineer.com/question.md?key=semester_5%2Finstrumentation_ii%3Asw-testing-paradox) — Instrumentation II, chapter 9
- [Hypothesis testing; difference of two proportions](https://www.bctengineer.com/question.md?key=semester_5%2Fprobability_and_statistics%3Ahypothesis-procedure-diff-two-proportions) — Probability and Statistics, chapter 7, asked 2×
