Testing Comparisonbeginner

Black Box vs White Box Testing

Black box testing checks what the software does without looking at code; white box testing checks how the code works inside. See both on one login page.

5 min read

Our verdict in 30 seconds

Black box testing checks the software from the outside: you give inputs and compare outputs with the requirements, without looking at the code. White box testing checks the inside: you read the code and design tests so that every statement, branch and path runs. Testers mostly do black box testing; developers do white box testing through unit tests. Real projects need both.

On This Page

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:

  1. Username is required.
  2. Password must have at least 8 characters.
  3. The correct username and password show a welcome message.
  4. 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 first if)
  • password = null (the first part of the second if)
  • 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?
Black box testing is mostly done by testers and sometimes by end users in acceptance testing. White box testing is mostly done by developers, usually as unit tests. Automation testers who can read code sometimes do both.
Is unit testing black box or white box?
Unit testing is usually white box, because the developer knows the code and writes tests to cover its branches. A unit test can also be designed only from the method's specification, which is black box thinking at the unit level.
What is grey box testing?
Grey box testing mixes both. The tester has partial knowledge of the inside, such as the database tables or API design, and uses it to design better black box tests. For example, checking that a sign-up form correctly saved a row in the users table.
Is manual testing black box testing?
Most manual functional testing is black box, since the tester uses the application through its screens. But manual and automation describe how a test is run, while black box and white box describe how a test is designed. An automated UI test is still black box.
What are black box testing techniques?
The common ones are equivalence partitioning, boundary value analysis, decision table testing, state transition testing and use case testing. Interviewers most often ask for examples of the first two.

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

Apply for Demo Class →
Siva Prasad Galaba
Founder, CodeBegun · Staff Engineer

Founder of CodeBegun. 15+ years building Java systems at companies like Crunchyroll. Teaches Java, Spring Boot and system design the way the industry actually works, and mentors students through projects, mock interviews and placement preparation.

Technically reviewed by CodeBegun Technical TeamLast reviewed 5 December 2026 LinkedIn

More comparisons

View all
Chat with us