Black box testing vs white box testing is about what the tester can see. In black box testing, the software is a closed box: you know what it should do from the requirements, you give it inputs, and you check the outputs. In white box testing, the box is open: you read the code and design tests that make every part of it run. One checks behaviour; the other checks the logic behind it.
Black box vs white box testing: the comparison table
| Point | Black box testing | White box testing |
|---|---|---|
| Also called | Behavioural, specification-based testing | Structural, glass box, clear box testing |
| Code knowledge needed | No | Yes |
| Tests are based on | Requirements, user stories, specifications | Code structure: statements, branches, paths |
| Done mostly by | Testers, end users | Developers |
| Main question | Does it do what it should? | Does every line and branch work correctly? |
| Typical levels | System and acceptance testing | Unit testing, some integration testing |
| Techniques | Equivalence partitioning, boundary values, decision tables | Statement, branch and path coverage |
| Finds | Missing features, wrong outputs, UI problems | Dead code, wrong conditions, untested branches |
| Misses | Hidden paths in the code nobody thought to test | Features that were never coded at all |
| Tools | Manual testing, Selenium, Postman | JUnit, TestNG, pytest, coverage tools like JaCoCo |
One login page, tested both ways
Requirement for a login page:
- Username is required.
- Password must have at least 8 characters.
- The correct username and password show a welcome message.
- Anything else shows "Invalid username or password".
Black box: test from the requirement only
The tester does not see any code. They design cases from the four rules:
| ID | Username | Password | Expected result | Technique |
|---|---|---|---|---|
| TC1 | (empty) | Secret@123 | Username is required | Required field check |
| TC2 | ravi | abc (3 chars) | Password must have at least 8 characters | Boundary: below minimum |
| TC3 | ravi | 7 characters | Password must have at least 8 characters | Boundary: just below 8 |
| TC4 | ravi | 8 characters, wrong | Invalid username or password | Boundary: exactly 8 |
| TC5 | ravi | Secret@123 | Welcome, ravi | Valid partition |
| TC6 | ravi | Wrong@123 | Invalid username or password | Invalid partition |
| TC7 | RAVI | Secret@123 | Ask: is username case-sensitive? | Unclear requirement |
TC3 and TC4 come from boundary value analysis: bugs gather at edges, so test just below, at and above the limit. TC5 and TC6 come from equivalence partitioning: valid and invalid credentials form two groups, and one test from each is enough. TC7 shows a real benefit of black box thinking: it exposes a gap in the requirement.
White box: test from the code
Now the developer looks at the code behind the page:
public class LoginCheck {
static String login(String username, String password) {
if (username == null || username.isBlank()) {
return "Username is required";
}
if (password == null || password.length() < 8) {
return "Password must have at least 8 characters";
}
if (username.equals("ravi") && password.equals("Secret@123")) {
return "Welcome, ravi";
}
return "Invalid username or password";
}
public static void main(String[] args) {
System.out.println(login("", "Secret@123"));
System.out.println(login("ravi", "abc"));
System.out.println(login("ravi", "Secret@123"));
System.out.println(login("ravi", "Wrong@123"));
}
}
Output:
Username is required
Password must have at least 8 characters
Welcome, ravi
Invalid username or password
The method has four exits (four return statements). The four calls in main reach each one, so every statement runs: that is 100% statement coverage.
But white box testing goes further. Each if has conditions joined with || or &&. To check each condition separately, the developer adds cases such as:
username = null(the first part of the firstif)password = null(the first part of the secondif)- a correct password with a wrong username (the left side of
&&is false)
These cases come from reading the code, not the requirement. A black box tester would rarely think of sending null, because the screen cannot send it, but an API or another class could.
Common mistake: Believing 100% coverage means no bugs. Coverage shows which code ran, not whether the code is correct. If the requirement said passwords need 10 characters and the code checks 8, every white box test can pass while the feature is still wrong. Only a black box test against the requirement catches that.
Coverage levels in white box testing
| Coverage | Goal | Login example |
|---|---|---|
| Statement | Every line runs at least once | 4 tests, one per return |
| Branch (decision) | Every if is both true and false |
The same 4 tests cover each if both ways here |
| Condition | Each part of a condition is both true and false | Add the null cases and the wrong-username case |
| Path | Every route from start to end | Practical only for small methods |
Tools such as JaCoCo for Java report these numbers after your JUnit or TestNG tests run.
Grey box testing: the middle ground
Grey box testing uses some inside knowledge without full code access. For the login page, a grey box tester might know that failed attempts are stored in a login_attempts table and check it after TC6. API testers often work this way, since they know the request and response structure and the database behind it.
Advantages and limits
Black box testing
- needs no programming, so testers and users can do it
- tests from the user's view and catches missing or wrong features
- cannot see untested code paths, and may repeat tests that cover the same code
White box testing
- finds logic errors, dead code and unhandled conditions early
- gives measurable coverage numbers
- needs coding skill, takes time, and cannot find features that were never written
That is why projects use both: developers write white box unit tests, and testers run black box system tests.
Where each fits in the testing levels
| Level | Usual approach |
|---|---|
| Unit testing | White box |
| Integration testing | Both, often grey box |
| System testing | Black box |
| Acceptance testing | Black box |
For how these levels fit the full life cycle, see SDLC and STLC interview questions.
Where to go next
Black box tests can be run by hand or by tools; read manual vs automation testing to see the difference. Most black box tests are functional, so functional vs non-functional testing is a natural next read. Prepare with manual testing interview questions and test case writing interview questions, and see the full career path in how to become a software tester.
Interview note: Use the login page: "In black box testing I would design cases from the requirement using boundary values, like 7, 8 and 9 character passwords. In white box testing, a developer reads the code and writes unit tests so each branch, including null inputs, is covered." Concrete examples score better than definitions.
Frequently Asked Questions
Who does black box and white box testing?
Is unit testing black box or white box?
What is grey box testing?
Is manual testing black box testing?
What are black box testing techniques?
Want to Build Your Career in Java Full Stack with AI?
Join CodeBegun and train with working industry engineers — View the Java Full Stack curriculum

