Black Box vs White Box Testing: Differences with Examples

By Ashish Mitra, QA engineer Published 17 min read

On this page
  1. In short
  2. Black box testing vs white box testing: the difference in one table
  3. What is black box testing?
  4. What is white box testing?
    1. What about grey box testing?
  5. Hands-on: test one coupon both ways
    1. Step 1: black box tests from the requirement
    2. Step 2: the code under test
    3. Step 3: run the black box tests with coverage
    4. Step 4: write a white box test for the untested branch
    5. What 100% coverage still does not tell you
  6. When to use black box and when to use white box
  7. Common mistakes testers make
  8. What the official docs say
  9. Black box and white box testing interview questions
    1. Can a tester do white box testing without being a developer?
    2. Which is better, black box or white box testing?
    3. What is the difference between statement and branch coverage?
    4. Give an example where black box testing finds a bug that white box misses.
  10. Frequently asked questions
    1. Is white box testing better than black box testing?
    2. What is an example of black box testing?
    3. Who performs white box testing?
    4. What is grey box testing?
  11. What to practise next
  12. Sources

Black box testing vs white box testing comes down to what you look at. Black box testing checks what the software does from the outside, using the requirements, without reading the code. White box testing checks how it works inside, using the code itself, and measures which lines and branches your tests actually ran. Most teams need both. Below, we test one food-delivery coupon both ways and show the real output, so you can see what each method catches and misses. For the hands-on part you need Node.js 22 or later; the rest needs nothing.

PassNode.js 22.23.5 with its built-in test runner and coverage, December 2026. Definitions checked against the ISTQB Foundation Level syllabus v4.0.1.

In short

  • Black box tests come from the requirement. You choose inputs and check outputs, and you never open the code.
  • White box tests come from the code. You read it, run your tests with coverage, and look for lines and branches nobody executed.
  • Black box finds missing or wrong behaviour. White box finds code that does something nobody asked for, or that no test ever touched.
  • 100% coverage only proves lines ran. It cannot tell you about a requirement the developer forgot to build.

Black box testing vs white box testing: the difference in one table

Take a UPI payment screen. A tester types ₹0, ₹1 and ₹1,00,001 into the amount box and checks what the app says. That is black box. A developer opens the validation function, sees an if for amounts above a limit, and makes sure some test goes through it. That is white box. Same screen, two very different ways of looking at it.

Black box testingWhite box testing
Based onRequirements, user stories, specified behaviourThe code and its internal structure
Do you need the code?NoYes, you read it
Who usually does itTesters, business analysts, users in UATDevelopers in unit tests, and testers who can read code
Common techniquesEquivalence partitioning, boundary value analysis, decision tables, state transitionStatement testing, branch testing
How you measure itPartitions, boundaries or rules coveredStatement and branch coverage %
Finds wellMissing features, wrong results, rules applied wronglyDead code, untested branches, extra logic nobody asked for
MissesHidden code paths that no requirement mentionsRequirements that were never coded
When code is refactoredTests usually still workTests may need updating
Typical patterns, not fixed rules. Who does what changes from team to team.

Other names you will hear: black box is also called specification-based or behaviour-based testing, and white box is called structure-based, glass box or clear box testing. NIST’s glossary lists several of these names for white box testing.

What is black box testing?

You get a requirement: “Passenger age must be between 5 and 120 for an adult ticket.” You don’t know, and don’t need to know, how the booking code handles it. You pick inputs, run them, and compare the result with the requirement. That is black box testing.

The ISTQB Foundation syllabus (v4.0.1, section 4.1) describes black box techniques as based on the specified behaviour of the test object, with no reference to its internal structure. It also points out a practical benefit: if the code is rewritten but the behaviour stays the same, the black box test cases are still useful.

The four black box techniques you should know for interviews:

  • Equivalence partitioning: split inputs into groups the system should treat the same way, and test one value from each group. Age below 5, 5 to 120, above 120 gives three partitions.
  • Boundary value analysis: test the edges of those groups, where developers most often slip with < and <=.
  • Decision table testing: list combinations of conditions and the expected result for each, useful for discount and eligibility rules.
  • State transition testing: test how something moves between states, like an order going from placed to preparing to out for delivery.

One detail worth learning properly is 2-value versus 3-value boundary analysis. With 2-value, for each boundary you test the boundary itself and its closest neighbour in the next partition. With 3-value, you test the boundary and both neighbours. The syllabus gives an example where a condition meant to be “x ≤ 10” was coded as “x = 10”. Testing 10 and 11 does not catch it; testing 9, which only the 3-value method adds, probably does.

What is white box testing?

Now flip it. You open the code and ask a different question: which parts of this did my tests actually run? White box techniques are built from the internal structure, so, as the syllabus notes, you can only create them once a design or the code exists.

Two coverage measures come up again and again. Statement coverage is the share of executable statements your tests ran. Branch coverage is the share of branches they took, where a branch means each way the program can go at a decision, such as both the true and the false side of an if. Branch coverage is the stronger of the two. The syllabus states that 100% branch coverage also gives you 100% statement coverage, but 100% statement coverage does not guarantee 100% branch coverage.

In most teams, developers write the unit tests that drive coverage numbers. That does not make white box testing a developer-only topic. A tester who can read a pull request, see a new if and ask “which test goes into this?” finds a class of bugs that requirement-based testing alone tends to miss.

What about grey box testing?

Most real testing sits somewhere in between. You might not read every line of code, but you know the API contract, the database tables or the log messages, and you use that to design sharper black box tests. Testers usually call this grey box testing. It is a common term in job interviews, but it is not one of the technique categories in the ISTQB Foundation syllabus, so expect interviewers to define it slightly differently.

Hands-on: test one coupon both ways

Here is a requirement from a made-up food-delivery app. Coupon FIRST50 gives 50% off, the discount is capped at ₹100, and it only works on carts of ₹199 or more. We will test it as a black box first, then open the code.

Step 1: black box tests from the requirement

Without reading any code, the requirement gives us partitions and boundaries:

PartitionBoundary values we pickExpected discount
Cart below ₹199₹198₹0
Cart ₹199 and above, discount under the cap₹199₹99 (50%, rounded down)
Discount reaches the cap₹200, ₹201₹100
Wrong coupon code₹500 with FIRST100“Invalid coupon”
Invalid cart total₹0Error
The requirement does not say how to round ₹99.50. We assumed rounding down; in a real project, ask the product owner.

Save this as coupon.blackbox.test.mjs. It uses Node’s built-in node:test and node:assert, so there is nothing to install.

// Black-box tests: written only from the spec, without reading coupon.mjs.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { applyCoupon } from './coupon.mjs';

test('Rs 198 is just below the minimum, so no discount', () => {
  assert.equal(applyCoupon(198, 'FIRST50').discount, 0);
});

test('Rs 199 is the minimum, so 50% off', () => {
  assert.equal(applyCoupon(199, 'FIRST50').discount, 99);
});

test('Rs 200 gives exactly the Rs 100 cap', () => {
  assert.equal(applyCoupon(200, 'FIRST50').discount, 100);
});

test('Rs 201 stays at the Rs 100 cap', () => {
  assert.equal(applyCoupon(201, 'FIRST50').discount, 100);
});

test('a wrong code gives no discount', () => {
  assert.equal(applyCoupon(500, 'FIRST100').message, 'Invalid coupon');
});

test('an empty cart is rejected', () => {
  assert.throws(() => applyCoupon(0, 'FIRST50'), /more than 0/);
});

Step 2: the code under test

This is the function the developer wrote. In a pure black box round you would not see it, but you need it to run the tests. Look at lines 13 to 16.

// FIRST50 coupon for a made-up food-delivery app.
// Spec: 50% off, maximum discount Rs 100, only on carts of Rs 199 or more.
export function applyCoupon(cartTotal, code) {
  if (typeof cartTotal !== 'number' || cartTotal <= 0) {
    throw new Error('Cart total must be more than 0');
  }
  if (code.toUpperCase() !== 'FIRST50') {
    return { discount: 0, payable: cartTotal, message: 'Invalid coupon' };
  }
  if (cartTotal < 199) {
    return { discount: 0, payable: cartTotal, message: 'Add items worth Rs 199 to use FIRST50' };
  }
  if (cartTotal > 5000) {
    // added later by a developer, not in the spec
    return { discount: 0, payable: cartTotal, message: 'Coupon applied' };
  }
  const discount = Math.min(Math.floor(cartTotal * 0.5), 100);
  return { discount, payable: cartTotal - discount, message: 'Coupon applied' };
}

Step 3: run the black box tests with coverage

Node’s test runner can collect coverage with one flag, as described in the Node.js guide to collecting code coverage. We also limit the report to coupon.mjs:

node --test --test-reporter=spec --experimental-test-coverage --test-coverage-include=coupon.mjs coupon.blackbox.test.mjs

Our real output:

✔ Rs 198 is just below the minimum, so no discount (1.533911ms)
✔ Rs 199 is the minimum, so 50% off (0.122461ms)
✔ Rs 200 gives exactly the Rs 100 cap (0.065665ms)
✔ Rs 201 stays at the Rs 100 cap (0.055513ms)
✔ a wrong code gives no discount (0.05649ms)
✔ an empty cart is rejected (0.374838ms)
ℹ tests 6
ℹ suites 0
ℹ pass 6
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 92.353489
ℹ start of coverage report
ℹ -----------------------------------------------------------
ℹ file       | line % | branch % | funcs % | uncovered lines
ℹ -----------------------------------------------------------
ℹ coupon.mjs |  84.21 |    90.00 |  100.00 | 14-16
ℹ -----------------------------------------------------------
ℹ all files  |  84.21 |    90.00 |  100.00 | 
ℹ -----------------------------------------------------------
ℹ end of coverage report

Every black box test passes. From the outside, the coupon looks done. The coverage report says something else: 90% branch coverage, and lines 14 to 16 never ran. That is the cartTotal > 5000 branch, which is not in the requirement at all.

Black box testing vs white box testing: the same coupon tested from the requirement and from the code, with one untested branch found by coverage
Black box tests checked the requirement. Coverage showed a branch none of them reached.

Step 4: write a white box test for the untested branch

Now we read the code on purpose. A white box test needs a cart above ₹5,000 to enter that branch, and ₹5,000 itself to stay on the normal path. The requirement has no upper limit, so the expected discount for both is still the ₹100 cap.

// White-box test: written after reading coupon.mjs and the coverage report.
// Lines 14-16 (the cartTotal > 5000 branch) were never run by the black-box tests.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { applyCoupon } from './coupon.mjs';

test('Rs 5001 goes through the > 5000 branch and should still get Rs 100 off', () => {
  // The spec has no upper limit, so the expected discount is the Rs 100 cap.
  assert.equal(applyCoupon(5001, 'FIRST50').discount, 100);
});

test('Rs 5000 stays on the normal path', () => {
  assert.equal(applyCoupon(5000, 'FIRST50').discount, 100);
});
node --test --test-reporter=spec --experimental-test-coverage --test-coverage-include=coupon.mjs coupon.blackbox.test.mjs coupon.whitebox.test.mjs
✔ Rs 198 is just below the minimum, so no discount (1.794706ms)
✔ Rs 199 is the minimum, so 50% off (0.117835ms)
✔ Rs 200 gives exactly the Rs 100 cap (0.1192ms)
✔ Rs 201 stays at the Rs 100 cap (0.063ms)
✔ a wrong code gives no discount (0.05879ms)
✔ an empty cart is rejected (0.374401ms)
✖ Rs 5001 goes through the > 5000 branch and should still get Rs 100 off (1.125795ms)
✔ Rs 5000 stays on the normal path (0.160074ms)
ℹ tests 8
ℹ suites 0
ℹ pass 7
ℹ fail 1
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 121.479918
ℹ start of coverage report
ℹ -----------------------------------------------------------
ℹ file       | line % | branch % | funcs % | uncovered lines
ℹ -----------------------------------------------------------
ℹ coupon.mjs | 100.00 |   100.00 |  100.00 | 
ℹ -----------------------------------------------------------
ℹ all files  | 100.00 |   100.00 |  100.00 | 
ℹ -----------------------------------------------------------
ℹ end of coverage report

✖ failing tests:

The failure details, trimmed to the useful part:

test at coupon.whitebox.test.mjs:7:1
✖ Rs 5001 goes through the > 5000 branch and should still get Rs 100 off (1.125795ms)
  AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
  
  0 !== 100

Coverage is now 100%, and the new test failed. A customer with a ₹5,001 cart sees “Coupon applied” but gets ₹0 off. That is a bug report, or at least a question for the product owner, and no black box test written from the requirement would have pointed you there, because the requirement never mentions ₹5,000.

What 100% coverage still does not tell you

Be careful with that 100%. It means every line and branch ran at least once. It does not mean the logic is right for every value, and it says nothing about features that were never built. The syllabus is clear on this: if the software does not implement a requirement, white box testing may not detect that omission. Suppose the real requirement also said “first order only” and the developer forgot it. There is no line to cover, so the coverage report stays green. Only a black box test from the requirement would catch it.

This is the honest trade-off. White box testing needs access to the code and someone who can read it, and coverage numbers can turn into a target people game. Black box testing is cheaper to start and closer to the user, but it is blind to logic nobody wrote down. Used together, each covers the other’s gap.

When to use black box and when to use white box

SituationBetter fitWhy
Testing a new feature against its user storyBlack boxYou are checking the promise made to the user
Reviewing a pull request with new conditionsWhite boxYou can see exactly which branches need a test
UAT or a release smoke checkBlack boxUsers and business testers rarely have the code
Unit tests and CI coverage gatesWhite boxCoverage tools work on code
A bug that only happens “sometimes”BothReproduce from outside, then read the code for the condition behind it
Discount, tax or eligibility rulesBothDecision tables from the rules, plus coverage to find hidden conditions

Common mistakes testers make

  • Treating coverage as proof of quality. 100% coverage means code ran, not that it is correct or complete. Missing requirements never show up as uncovered lines.
  • Testing only one value per field. Black box testing without boundaries misses the classic < versus <= slip. Test both sides of every edge.
  • Saying white box is “only for developers”. Reading a diff and asking which test covers a new branch is one of the most useful things a tester can do.
  • Mixing up testing types and testing levels. Black box and white box describe how you design tests. Unit, integration and system describe where you test. You can do black box testing at the unit level too.
  • Guessing an expected result. If the requirement is silent, like the ₹99.50 rounding in our example, write down the assumption and ask, instead of quietly picking one.

What the official docs say

The ISTQB Certified Tester Foundation Level syllabus v4.0.1 (September 2024) is the main reference here. Section 4.1 splits techniques into black box, white box and experience-based. Section 4.2 covers equivalence partitioning, boundary value analysis, decision tables and state transitions. Section 4.3 covers statement and branch testing and explains both the value and the limits of white box testing. The ISTQB CTFL v4.0 page lists the current syllabus version.

For the other names of white box testing, see the NIST CSRC glossary. The coverage flags we used are explained in the Node.js guide on collecting code coverage, and the Node.js releases page shows which versions are currently supported. Who does which kind of testing is our view of how most teams work, and yours may differ.

Black box and white box testing interview questions

Can a tester do white box testing without being a developer?

Yes, at a basic level. You need to read the code well enough to see conditions and branches, and know how to read a coverage report. You do not need to write production code. Reviewing a diff and adding tests for each new branch is a good start.

Which is better, black box or white box testing?

Neither on its own. Black box checks the software against the requirement and catches missing behaviour. White box checks the code and catches untested or unexpected logic. Our coupon example needed both to find all its problems.

What is the difference between statement and branch coverage?

Statement coverage counts how many statements ran. Branch coverage counts how many decision outcomes ran, like both sides of an if. Full branch coverage includes full statement coverage, but not the other way round.

Give an example where black box testing finds a bug that white box misses.

A requirement says the coupon is for first orders only, and the developer never coded that check. There is no line for coverage to flag, but a black box test with a returning customer fails straight away.

Frequently asked questions

What is the main difference between black box and white box testing?

Black box testing designs tests from the requirements and checks inputs and outputs without looking at the code. White box testing designs tests from the code itself and measures which statements and branches the tests executed. Black box finds wrong or missing behaviour; white box finds untested or unexpected logic.

Is white box testing better than black box testing?

No, they answer different questions. White box shows which code your tests reached, but it cannot find requirements that were never built. Black box checks behaviour against the requirement, but it cannot see hidden code paths. Most teams use both, often black box by testers and white box in unit tests.

What is an example of black box testing?

Testing an age field that accepts 5 to 120 by entering 4, 5, 120 and 121 and checking the result, without reading the code. That uses equivalence partitioning and boundary value analysis, two common black box techniques that work on any form, API or screen.

Who performs white box testing?

Usually developers, through unit tests and coverage reports in CI. Testers can do it too when they read code, review pull requests and add tests for untested branches. The exact split depends on the team, its tools and how much code access testers have.

What is grey box testing?

Grey box testing is a common name for testing with partial knowledge of the inside, such as the API contract, database tables or logs, while still testing mostly from the outside. It is widely used in interviews, but it is not a separate technique category in the ISTQB Foundation syllabus.

What to practise next

Pick any screen you test at work, write black box cases for it with boundaries in our test case template, and then ask a developer for the coverage report of the same feature. Compare the two lists. Our UPI payment test cases are good practice for boundary values on amounts, and the chatbot testing guide shows black box checks on a system whose answers change every time.

If you are preparing for interviews, the interview prep questions cover these basics, and more guides are in the Manual Testing section.

Sources

  1. ISTQB – Certified Tester Foundation Level Syllabus v4.0.1, sections 4.1 to 4.3 (2024)
  2. ISTQB – Certified Tester Foundation Level (CTFL) v4.0 (2026)
  3. NIST CSRC – Glossary: White Box Testing (from NIST SP 800-137 and SP 800-192)
  4. Node.js – Collecting code coverage in Node.js (Node.js Learn, 2026)
  5. Node.js – Node.js Releases (2026)

Tools and features change often. Check the official documentation for the version you are using.

Test yourself on this topic

Next in the path · Step 2, API Testing Playwright vs Postman for API Testing

The same four API checks written in both Postman and Playwright, with real output, so you can see exactly what…

Ashish Mitra

QA engineer, manual and automation testing

Writes every TesterPath guide from hands-on work. About TesterPath