Testing fundamentals

Black Box vs White Box Testing: Differences, Techniques and Examples

Robonito TeamRobonito Team 10 min read
Black Box vs White Box Testing: Differences, Techniques and Examples

A tester and a developer look at the same checkout bug. The tester says, "I typed an 11-character code and it was accepted. The spec says 10 is the max." The developer opens the function and says, "The max-length check is off by one, and none of our unit tests ever made it fire." Both are right. They just tested from different sides of the box.

That is the whole debate in one bug. One person tested what the feature should do. The other tested how the code does it. You need both, and the useful question is which one to use where.

Updated December 2026

Black box vs white box testing comes down to what the tester can see. Black box testing checks behavior against the requirements without looking at the code. White box testing designs tests from the code itself, aiming for statement, branch, condition or path coverage. Black box finds missing or wrong features. White box finds untested logic.

Key takeaways

  • Black box testing uses the spec. White box testing uses the source code. Grey box uses partial knowledge, such as the API contract or database schema.
  • The core black box techniques are equivalence partitioning, boundary value analysis, decision tables, state transitions and use cases. The core white box techniques are statement, branch, condition and path coverage.
  • This guide runs every technique on one feature, a discount-code field, so you can see the actual partitions, table rows, code and test cases.
  • Use white box at the unit level and black box at the system and acceptance levels. Most teams need both, because each one misses what the other catches.

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

The ISTQB Foundation syllabus puts it cleanly. Black-box techniques are "based on an analysis of the specified behavior of the test object without reference to its internal structure." White-box techniques are based on the test object's "internal structure and processing" (ISTQB CTFL v4.0.1, section 4.1).

Two consequences follow from that definition, and they matter more than any list of pros and cons:

  • Black box tests survive refactoring. If the code changes but the required behavior doesn't, the tests still apply.
  • White box tests can only be written after the code exists. They depend on the design, so they change when the design changes.

The same syllabus adds a third family, experience-based techniques (error guessing, exploratory testing, checklists), which complement both. If you want the bigger map, our guide to types of software testing places all three in context.

Most top-ranking articles on black box vs white box testing stop at definitions and a list of technique names. Below, every technique is applied to the same feature, with real values, so you can copy the pattern into your own test cases.

The example feature: a discount-code field

Here is the spec we'll test. It's small, but it has ranges, rules, states and a flow, which is all you need to show every technique.

RuleSpec
R1. FormatA code is 6 to 10 characters, letters and digits only. Codes are not case sensitive.
R2. ValidityThe code must exist and must not be expired.
R3. Minimum orderThe cart subtotal must be at least $20.00.
R4. DiscountEach code gives between 10% and 50% off, set by an admin. Members get 5 extra points, capped at 50%.
R5. LockoutAfter 3 failed attempts in a session, the field locks for 15 minutes.
R6. One codeOnly one code can be applied per order.

Which black box testing techniques should you use?

Black box testing works from rules R1 to R6 alone. You never open the code.

Equivalence partitioning

Split each input into groups the system should treat the same way, then test one value per group. If one value in a partition passes, the theory says the rest will too.

InputPartitionValid?Test value
Code length0 characters (empty)Invalid""
Code length1 to 5 charactersInvalidSAVE
Code length6 to 10 charactersValidSAVE20
Code length11 or more charactersInvalidSAVE20EXTRA
CharactersLetters and digits onlyValidSAVE20
CharactersContains a symbol or spaceInvalidSAVE-20
CaseLowercase version of a real codeValidsave20
SubtotalBelow $20.00Invalid$12.00
Subtotal$20.00 or moreValid$64.00
Code statusExists and activeValidSAVE20
Code statusDoes not existInvalidNOSUCH1
Code statusExpiredInvalidSUMMER24

Twelve tests cover twelve partitions. Notice the invalid rows. Those are your negative tests, and they're where most real defects in input fields live.

Boundary value analysis

Defects cluster at the edges of partitions, where someone typed < instead of <=. ISTQB describes two versions (section 4.2.2). 2-value BVA tests each boundary and its nearest neighbor in the next partition. 3-value BVA tests the boundary and both neighbors, which catches more off-by-one bugs.

Here is 3-value BVA for our field:

BoundaryValues to testExpected result
Minimum length (6)5, 6, 7 charactersReject, accept, accept
Maximum length (10)9, 10, 11 charactersAccept, accept, reject
Minimum subtotal ($20.00)$19.99, $20.00, $20.01Reject, accept, accept
Minimum discount (10%)9%, 10%, 11% (admin screen)Reject, save, save
Maximum discount (50%)49%, 50%, 51% (admin screen)Save, save, reject
Member cap (50%)Member with a 44%, 45%, 46% code49%, 50%, 50% off

The member-cap row is easy to miss. It isn't an input field at all. It's a boundary inside a calculation, and you only find it by reading R4 carefully.

Decision table testing

When the outcome depends on a combination of conditions, list the combinations. A dash means "doesn't matter for this rule."

Condition / actionRule 1Rule 2Rule 3Rule 4Rule 5
Format valid (R1)NYYYY
Code exists (R2)–NYYY
Code not expired (R2)––NYY
Subtotal ≥ $20.00 (R3)–––NY
Message"Codes are 6 to 10 letters or digits""Code not recognized""This code has expired""Add $X more to use this code"Discount applied
Counts as failed attempt?NoYesYesNoNo

Five rules, five test cases. The last row is where the table pays off. Writing it forces a question the spec didn't answer: does a badly formatted code count toward the lockout? Take that question to the product owner before you write a single test.

State transition testing

The lockout rule (R5) makes the field a small state machine.

Current stateEventNext stateVisible result
S0: Ready, 0 failuresValid codeAppliedNew total shown
S0: Ready, 0 failuresInvalid codeS1: 1 failureError message
S1: 1 failureInvalid codeS2: 2 failuresError message
S1: 1 failureValid codeAppliedNew total, counter resets
S2: 2 failuresInvalid codeLocked"Try again in 15 minutes"
LockedAny codeLockedField disabled
Locked15 minutes passS0: ReadyField enabled
AppliedRemove codeS0: ReadyOriginal total shown
AppliedSecond codeApplied"Only one code per order" (R6)

Testing each row once gives you what ISTQB calls 0-switch coverage, every valid transition exercised at least once. The "Locked + any code" and "Applied + second code" rows are the invalid transitions, the ones users trigger by accident and developers forget to block.

Use case testing

Use cases test the flow end to end, with a main path and alternates. (ISTQB moved use case testing out of the v4 Foundation syllabus into the Advanced Test Analyst one, but it's still widely used for system tests.)

Main flow: Shopper adds $64 of items, enters SAVE20, clicks Apply, sees $51.20, pays $51.20.

Alternate flows:

  1. Shopper enters an expired code, sees the expiry message, enters a valid one, and the discount applies.
  2. Shopper applies SAVE20 on a $25 cart, then removes an item so the subtotal drops to $15. The discount should be removed with a message, not silently kept.
  3. Shopper applies a code, refreshes the page, and the discount is still there.

Alternate flow 2 is the one that ships as a bug. No input-level technique finds it, because every individual input was valid. If you want a format for writing these up, see how to write test cases in manual testing.

How do white box testing techniques work on the same feature?

Now open the box. Here is a simplified version of the code behind the field. The decisions are labeled D1 to D5.

def apply_discount(code, subtotal, codes, attempts, is_member):
    if attempts >= 3:                                          # D1
        return "locked"
    if len(code) < 6 or len(code) > 10 or not code.isalnum():  # D2
        return "bad_format"
    promo = codes.get(code.upper())
    if promo is None or promo.expired:                         # D3
        return "invalid"
    if subtotal < 20:                                          # D4
        return "below_minimum"
    percent = promo.percent
    if is_member:                                              # D5
        percent = min(percent + 5, 50)
    return round(subtotal * (100 - percent) / 100, 2)

Assume codes holds SAVE20 (20%, active) and SUMMER24 (15%, expired).

Statement coverage

Every executable line runs at least once. Five tests do it:

TestInputsResultNew lines covered
T1attempts = 3"locked"D1 return
T2code = SAVE"bad_format"D2 return
T3code = NOSUCH1"invalid"lookup, D3 return
T4SAVE20, subtotal = 15"below_minimum"D4 return
T5SAVE20, subtotal = 100, member75.0percent, D5 body, final return

That's 100% statement coverage. It still leaves a gap. No test runs D5 as false, so a bug that only hits non-members goes unseen. ISTQB makes the same point: 100% statement coverage "does not ensure that all the decision logic has been tested" (section 4.3.1).

Branch coverage

Every decision takes both its true and false outcome. Add one test:

TestInputsResultNew branch covered
T6SAVE20, subtotal = 100, not a member80.0D5 false

Six tests, 100% branch coverage. Branch coverage always includes statement coverage, but not the reverse.

Condition coverage

Branch coverage treats D2 as one yes-or-no question. It's really three conditions joined by or. T2 makes D2 true using only the first one (len < 6). So the checks for len > 10 and not isalnum() have never been true. If the developer had written len(code) > 11, every test so far would still pass. That's the bug from the opening.

Condition coverage makes each atomic condition true and false at least once:

TestInputsCondition made trueResult
T7SAVE20EXTRA (11 characters)len(code) > 10"bad_format"
T8SAVE-20not code.isalnum()"bad_format"
T9SUMMER24promo.expired (D3)"invalid"

Note that T7 and T8 match values from the black box partitions above. The two methods meet in the middle. Stricter variants exist, such as modified condition/decision coverage (MC/DC), where each condition must be shown to change the outcome on its own.

Path testing

A path is one complete route from entry to exit. This function has no loops, so the paths are easy to count:

PathRouteTest
P1D1 trueT1
P2D1 false, D2 trueT2
P3D1, D2 false, D3 trueT3
P4D1 to D3 false, D4 trueT4
P5D1 to D4 false, D5 trueT5
P6D1 to D4 false, D5 falseT6

Six paths, which matches the cyclomatic complexity: five decisions plus one. Path testing adds little here because the early returns keep paths separate. It earns its place in code with loops and decisions that don't return, where the number of paths grows much faster than the number of branches.

Coverage levelTests needed hereWhat it still misses
Statement5 (T1–T5)D5 false; untested conditions in D2 and D3
Branch6 (T1–T6)len > 10, symbols, expired codes
Condition9 (T1–T9)Data-dependent bugs, such as rounding on $0.01 carts
Path6 here, many more with loopsAnything not in the code, such as R6 or alternate flow 2

That last cell is the key limit of white box testing. Code coverage only measures the code that exists. The missing "remove discount when subtotal drops" logic has no line to cover.

What is grey box testing?

Grey box testing sits between the two. The tester knows some internals, such as the API contract, database schema or architecture, but still tests through the public interface.

For our field, a grey box tester who has read the schema and API spec might add:

  • Case handling. The code is stored uppercase and the lookup calls upper(). So test save20, Save20 and a code with a Turkish dotted I, where uppercasing behaves differently.
  • Lockout scope. The attempts counter is stored per session, not per account. Opening a new browser session resets it, which is a brute-force risk worth reporting.
  • API bypass. Send POST /cart/discount directly with a 50-character code to check the server repeats the length check the UI already enforces.

It is common in integration testing, API testing and security testing, where knowing the contract tells you which inputs are worth sending.

Black box vs white box testing: how do they compare side by side?

Black boxWhite boxGrey box
Tests againstRequirements and specSource code and designSpec plus partial internals
Knowledge neededDomain and requirements, no codeProgramming, the codebaseAPI contracts, schemas, architecture
Usually done byQA engineers, business analysts, end usersDevelopers, SDETsQA engineers, SDETs, security testers
Main levelsSystem, acceptance, end-to-endUnit, componentIntegration, API, security
TechniquesPartitioning, BVA, decision tables, state transition, use casesStatement, branch, condition, path coverageBlack box techniques guided by known internals
Coverage measured asRequirements or rules coveredStatements, branches or conditions executedBoth, informally
Example toolsSelenium, Playwright, API clientscoverage.py, JaCoCo, IstanbulAPI clients, database queries, proxies
When tests can be writtenAs soon as the spec existsAfter the code existsAfter the interfaces are defined
Survives refactoringYes, if behavior is unchangedOften needs updatesMostly
Finds bestMissing features, wrong behavior, usability issuesDead code, untested branches, logic errorsIntegration faults, data issues, security gaps
MissesHidden logic paths, untested codeMissing requirements, wrong specDeep code paths, full user journeys
Main costCan't see what wasn't tested insideNeeds coding skill, breaks on redesignNeeds access to internals and docs

A few tool notes from the vendors' own docs. coverage.py measures statement coverage and adds branch coverage with the --branch flag. JaCoCo reports instruction, branch, line, method and class counters plus cyclomatic complexity. Selenium WebDriver drives Chrome, Firefox, Edge and Safari. Playwright drives Chromium, Firefox and WebKit from TypeScript, Python, .NET or Java.

When should you use black box vs white box testing?

Use this as a starting decision table for your own test levels:

SituationStart withWhy
Writing unit tests for new business logicWhite box (branch coverage)You own the code and can see every decision
Testing a feature against its acceptance criteriaBlack box (partitions, BVA, decision tables)The criteria are the spec
Rules with many combined conditions (pricing, eligibility)Black box decision tables, then white box condition coverageTables find missing rules, conditions find untested logic
Workflows with steps and statuses (orders, approvals, logins)Black box state transition and use casesBugs hide in the transitions, not single inputs
Testing APIs and service contractsGrey boxThe contract tells you which inputs matter
Testing a third-party or vendor app you can't see insideBlack boxIt's your only option
Regression suite that must survive refactorsBlack box at the UI and API levelTests don't depend on implementation
Safety-critical or security-sensitive codeBoth, with stricter condition coverageEach misses defects the other catches

In practice, black box vs white box testing splits by role. Developers own white box testing in unit tests and track coverage in CI. QA owns black box testing at the system level. The weak spot is the middle, where nobody owns the alternate flows. That's where a functional testing plan earns its keep.

Where does Robonito fit?

In black box vs white box testing terms, Robonito is a black box tool, and we'd rather say so plainly.

Robonito is an agentic QA platform. Its AI agents create, run and maintain end-to-end tests from the outside, through the UI and the API. In AI Studio you describe what to test, paste a URL or reference a Jira issue, and the agent works through the app step by step. It can also generate tests from requirement documents, Jira stories, Swagger/OpenAPI definitions and the live app. That suits the black box techniques above. You can describe the decision table rows or the alternate flows in plain language and get runnable tests.

For API-level and grey box style checks, you can import Postman collections. API testing is on the Pro and Enterprise plans, while web testing is on every plan, including Free. Steps self-heal when labels, layouts or locators change, and healed steps are logged for review, which helps black box suites survive UI redesigns.

Where it doesn't fit: Robonito doesn't measure code coverage. It won't tell you that D5 was never false or that a condition in D2 never fired. Keep your unit tests and a coverage tool such as coverage.py or JaCoCo for that. It also isn't a test management tool. It integrates with TestRail and Zephyr for that.

See how it handles end-to-end suites on the automation testing tool page, or compare options in our API test automation tools guide.

·

Frequently asked questions

Is black box testing the same as functional testing?

No, but they overlap. Black box testing describes how you design tests (from the spec, without the code). Functional testing describes what you test (features and behavior). Most functional tests are black box, but non-functional tests such as performance and usability checks can be black box too.

Is unit testing white box or black box?

Usually white box, because developers write unit tests while looking at the code and measure branch coverage. But you can design unit tests from a function's documented contract alone, which is black box testing at the unit level.

Which is better, black box or white box testing?

Neither. The black box vs white box testing question is about fit, not ranking. White box testing finds untested logic in code that exists. Black box testing finds behavior that's missing or wrong, including code nobody wrote. The worked example above shows each one catching a defect the other missed.

Does 100% code coverage mean the software is fully tested?

No. 100% statement coverage can still miss whole branches, and 100% branch coverage can miss individual conditions. Even full path coverage can't detect missing requirements, because there's no code to cover.

Can black box testing be automated?

Yes. Browser tools such as Selenium and Playwright, API clients and agentic platforms all run black box tests. The techniques in this guide (partitions, boundaries, tables) decide what to test. Automation decides how often it runs.

Is penetration testing black box or white box?

It can be either. In black box penetration testing the tester starts with no inside knowledge, like an outside attacker. White box penetration testing gives the tester source code and architecture. Grey box, with credentials and API docs, is a common middle ground.

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

A grey box tester knows some internals but still tests through the public interface. A white box tester designs tests directly from the code and measures which lines and branches ran.


Want black box tests for your UI and API without writing locators? or .

Free whitepaperThe Agentic QA PlaybookMove from test scripts to AI agents in 90 days, with the controls, metrics and a 25-question vendor checklist.

No-code AI test automation

Spend less time testing and more time shipping.

3Pillar showed Robonito's agents to its own client live, and that client is now onboarding. Start on the Free plan, which stays free forever, or book a demo and we'll walk through your own app.

Newsletter

Get new posts by email

Practical guides on software testing, QA automation and AI agents. One email when we publish, no spam.

We'll send a confirmation email first. Your details are stored with Mailchimp, our email provider.

All blog posts