1. Home
  2. Blog
  3. Software Testing

Software Testing

Boundary Value Analysis: Technique, Examples and Test Cases

Most input bugs hide at the edges of a range, not in the middle. Learn boundary value analysis with a worked example, the exact values to test and code you can run.

7 min read
Boundary value analysis: technique, examples and test cases

Key takeaways

  • Boundary value analysis (BVA) tests the values at and next to the edges of an input range.
  • For a valid range 18 to 60, test 17, 18, 19, 59, 60 and 61.
  • Developers often make off-by-one errors with < and <=, and mid-range values never catch them.
  • Use BVA together with equivalence partitioning to keep the test set small and strong.

Ask a developer to check “age must be between 18 and 60” and the code is usually right for 30 and 45. It breaks at 18 or 60, where one wrong comparison operator changes the result. Boundary value analysis exists to find exactly those bugs.

It is a black-box test design technique, so you need no access to the code, only the requirement. For a different way to design cases from rules, see our guide to decision table testing.

What boundary value analysis is

BVA is based on a simple observation: errors cluster at the boundaries of input ranges. Instead of testing many random values, you test the smallest and largest valid values and the values just outside them.

There are two common versions. Two-point BVA tests each boundary and the value just outside it. Three-point BVA adds the value just inside the boundary, which gives stronger coverage at a small cost.

A worked example: registration age

The requirement: users must be 18 to 60 years old to register. The valid range is 18 to 60, so the boundaries are 18 and 60.

Input age Position Expected result
17 Just below the lower boundary Rejected
18 Lower boundary Accepted
19 Just above the lower boundary Accepted
59 Just below the upper boundary Accepted
60 Upper boundary Accepted
61 Just above the upper boundary Rejected

Six cases cover the whole range. Testing 25, 30 and 45 would add almost no information.

Which values to pick

  1. Find the valid range and write down its minimum and maximum.
  2. Take the minimum and the maximum themselves.
  3. Take one step below the minimum and one step above the maximum. The step is 1 for whole numbers, 0.01 for money, one second for time.
  4. For three-point BVA, also take one step inside each boundary.
  5. Write the expected result for every value before you run it.

Tip: the “step” depends on the data type. For a price field that allows two decimals, the value just above 100.00 is 100.01, not 101.

Run it in Python

Here is the rule as code, with our six cases as checks. We ran this on Python 3.13, and every line passes.

def can_register(age):
    return 18 <= age <= 60

cases = {17: False, 18: True, 19: True, 59: True, 60: True, 61: False}
for age, expected in cases.items():
    assert can_register(age) == expected
    print(age, can_register(age))

# 17 False
# 18 True
# 19 True
# 59 True
# 60 True
# 61 False

Now introduce the classic off-by-one bugs and see which tests catch them.

def buggy_lower(age):
    return 18 < age <= 60     # should be >=

def buggy_upper(age):
    return 18 <= age < 60     # should be <=

print([a for a in cases if buggy_lower(a) != cases[a]])   # [18]
print([a for a in cases if buggy_upper(a) != cases[a]])   # [60]
print([a for a in (25, 40) if buggy_lower(a) != can_register(a)])   # []

The first bug is caught only by 18, the second only by 60, and the mid-range ages 25 and 40 find nothing. That is the whole case for BVA in four lines.

Pair it with equivalence partitioning

Equivalence partitioning splits inputs into groups that the system should treat the same, such as “below 18”, “18 to 60” and “above 60”. BVA then picks the edge values of each group. Partitioning chooses the groups, BVA chooses the best values inside them. Put the resulting cases into the format from our guide on how to write test cases.

Where else boundary value analysis applies

  • Text length: a username of 3 to 20 characters means testing 2, 3, 4, 19, 20 and 21 characters.
  • Quantities and prices: minimum order, free-shipping thresholds, coupon limits.
  • Dates and times: the first and last day of a month, midnight, leap days.
  • Files and pages: maximum upload size, last page of a paginated list.
  • APIs: limits, offsets and rate limits. Pair this with API testing with Postman.

Common mistakes

  • Testing only the valid boundaries. The values just outside the range matter as much.
  • Using the wrong step. A decimal field needs a decimal step.
  • Trusting the UI alone. A form may block 61 while the API still accepts it. Test both layers.
  • Forgetting hidden boundaries. Think of database column sizes and integer limits.

Final thoughts

Boundary value analysis is cheap, fast and effective. Write the six edge values for every range in your requirements and you will catch more bugs than a long list of random inputs.

Frequently asked questions

What is boundary value analysis in software testing?

It is a black-box test design technique that tests values at and around the edges of input ranges, because defects are most likely to appear there.

How many test cases does BVA need for one range?

Two-point BVA needs four values for a closed range, and three-point BVA needs six: below, on and above each boundary.

What is the difference between boundary value analysis and equivalence partitioning?

Equivalence partitioning divides inputs into groups that behave the same. Boundary value analysis picks the edge values of those groups, where bugs are most common.

Can BVA be used for non-numeric data?

Yes. Apply it to anything with an ordered limit, such as string length, dates, file size or list length.

Should I automate boundary tests?

Yes. They are small, deterministic and ideal for data-driven tests, so one test function can run many boundary values.

Keep learning

Work with Stack Quora

Need help with testing, WordPress or SEO?

We help teams ship better software and grow their sites. Tell us what you are working on and we will suggest a clear next step.

Keep reading

More guides on testing, AI & modern development

Enjoyed this article? Pick a topic and jump straight into our newest tutorials.

Artificial Intelligence

LLM Structured Output Explained: Getting Reliable JSON From AI Models

LLM structured output explained with validation we ran in Pydantic: JSON mode and schemas, constrained decoding, the ways model output…

Read article →
DevOps

SSH Keys Explained: How They Work, ssh-keygen, Ed25519 and Safe Habits

SSH keys explained with keys we generated: public vs private keys, ssh-keygen, Ed25519 vs RSA, fingerprints, passphrases, ssh-agent, authorized_keys, config…

Read article →
DevOps

HTTP Caching Explained: Cache-Control, ETag and 304 Responses, With a Live Test

HTTP caching explained with a small server we ran: Cache-Control directives, max-age, no-cache vs no-store, ETag revalidation and 304 responses,…

Read article →
Test Automation

API Contract Testing Explained: Catch Breaking Changes Before They Ship

API contract testing explained with a schema check we ran: what a contract is, consumer-driven contracts, Pact, OpenAPI, which changes…

Read article →
Software Testing

Risk-Based Testing Explained: Score Risks, Build a Matrix and Test What Matters

Risk-based testing explained step by step: identifying risks, scoring likelihood and impact, building a risk matrix, mapping risk to test…

Read article →
Databases & SQL

SQL Constraints Explained: NOT NULL, UNIQUE, CHECK and FOREIGN KEY, Tested

SQL constraints explained with tests we ran: NOT NULL, UNIQUE, CHECK, DEFAULT, PRIMARY and FOREIGN KEY, the NULL loopholes, SQLite's…

Read article →
Databases & SQL

SQL Date Functions Explained: Adding, Comparing and Grouping Dates Without Bugs

SQL date functions explained with queries we ran: adding intervals, month-end surprises, date differences, the BETWEEN trap, grouping by day,…

Read article →
Software Development

Python asyncio Explained: async, await, gather and TaskGroup With Real Timings

Python asyncio explained with code we timed: coroutines, await, gather, TaskGroup, error handling, timeouts, limiting concurrency and the blocking-call mistake…

Read article →
Software Development

Debounce vs Throttle in JavaScript: How They Work, When to Use Each, Tested

Debounce vs throttle in JavaScript explained with timings we measured in Node.js: how each works, simple implementations, leading and trailing…

Read article →
Software Development

Python Context Managers Explained: The with Statement, contextlib and Real Uses

Python context managers explained with code we ran: how with works, __enter__ and __exit__, contextlib.contextmanager, suppress, ExitStack, database transactions and…

Read article →
Artificial Intelligence

LLM Temperature and Top-p Explained: How AI Models Choose Their Next Word

LLM temperature and top-p explained with a simulation we ran: how probabilities are reshaped, what top-p keeps, recommended settings by…

Read article →
DevOps

YAML Explained: Syntax, the Norway Problem and Other Traps We Tested

YAML explained with a parser test: basic syntax, lists and maps, the Norway problem, versions turning into floats, octal zip…

Read article →
DevOps

Cron Jobs Explained: Syntax, Real Schedules and the Mistakes That Break Them

Cron jobs explained with schedules we verified: the five fields, operators, real examples, the day-of-month OR day-of-week trap, environment problems,…

Read article →
Software Testing

Bug Life Cycle in Software Testing: Every Status, Who Owns It and Common Mistakes

The bug life cycle explained: every defect status from New to Closed, who owns each step, rejected, deferred and reopened…

Read article →
Test Automation

Property-Based Testing in Python: Hypothesis Finds the Bugs Your Examples Miss

Property-based testing explained with Hypothesis tests we ran: properties vs examples, strategies, shrinking, the real bugs it found in our…

Read article →
Databases & SQL

SQL Pagination Explained: OFFSET vs Keyset, With a Million-Row Test

SQL pagination explained with a million-row test we ran: LIMIT and OFFSET, why deep pages get slow, keyset (cursor) pagination,…

Read article →
Databases & SQL

SQL EXISTS vs IN: Differences, the NOT IN NULL Trap and Performance

SQL EXISTS vs IN explained with queries we ran: how each works, why NOT IN returns no rows when a…

Read article →
Software Development

Python Logging Explained: Levels, Handlers, Formatters and Mistakes to Avoid

Python logging explained with code we ran: levels, basicConfig quirks, named loggers, handlers and formatters, logger.exception, lazy formatting, duplicate logs…

Read article →
Software Development

JavaScript Map vs Object: Key Differences, Pitfalls and a Benchmark

JavaScript Map vs Object explained with code we ran in Node.js: key types, ordering, the prototype trap, JSON, size, WeakMap…

Read article →
Software Development

Python Type Hints Explained: Annotations, mypy and the Errors It Catches

Python type hints explained with a real mypy run: basic annotations, Optional and unions, TypedDict, Literal, Protocol, generics, Callable, strict…

Read article →
Artificial Intelligence

LLM Tokens Explained: How AI Models Read Text, Count Costs and Fill Context Windows

LLM tokens explained with a tokenizer we ran: how text is split, why counts differ by language and tokenizer, context…

Read article →
DevOps

Semantic Versioning Explained: MAJOR.MINOR.PATCH, Ranges and Release Rules

Semantic versioning explained with code we ran: MAJOR.MINOR.PATCH rules, pre-releases, correct version sorting, caret and tilde ranges, 0.x versions, lockfiles…

Read article →
DevOps

Git Reset vs Revert: How to Undo Commits Safely, With a Tested Example

Git reset vs revert explained with a repository we built: soft, mixed and hard reset, revert commits, reverting merges, recovering…

Read article →
Software Testing

The Test Pyramid Explained: Layers, Ratios and When to Break the Shape

The test pyramid explained: unit, integration and end-to-end layers, sensible ratios, the ice cream cone anti-pattern, the testing trophy and…

Read article →
Test Automation

pytest Fixtures Explained: Scope, yield Teardown, conftest.py and Factories

pytest fixtures explained with a suite we ran: how fixtures work, scopes, yield teardown, conftest.py, factory fixtures, parametrized fixtures, built-ins…

Read article →
Databases & SQL

SQL Upsert Explained: INSERT ON CONFLICT, MERGE and the REPLACE Trap

SQL upsert explained with queries we ran: INSERT ON CONFLICT DO UPDATE and DO NOTHING, the excluded row, conditional updates,…

Read article →
Databases & SQL

SQL LIKE Operator Explained: Wildcards, Case Sensitivity and Performance

The SQL LIKE operator explained with queries we ran: % and _ wildcards, escaping, NOT LIKE and NULL, case sensitivity…

Read article →
Artificial Intelligence

AI Hallucinations Explained: Why Language Models Make Things Up and How to Reduce It

AI hallucinations explained: what they are, why language models produce them, common types, how to reduce them with grounding and…

Read article →
Test Automation

Mocking in Python: unittest.mock, patch and the Mistakes That Make Tests Lie

Mocking in Python with unittest.mock, tested: Mock and return_value, side_effect, patching where a name is used, spec and autospec, mocking…

Read article →
Software Testing

Code Coverage Explained: Line vs Branch Coverage and What 100% Really Means

Code coverage explained with a real coverage.py run: line, branch and condition coverage, reading a report, why 100% coverage can…

Read article →
Artificial Intelligence

What Are AI Agents? How They Work, With a Simple Agent Loop You Can Run

What are AI agents? A plain guide to the agent loop, tools, memory and guardrails, with a small Python loop…

Read article →
Test Automation

TDD vs BDD: Key Differences, One Feature Built Both Ways and When to Use Each

TDD vs BDD explained with one discount feature built both ways: red-green-refactor with code we ran, Given-When-Then scenarios, tools, trade-offs…

Read article →
Software Testing

User Acceptance Testing (UAT): Process, Checklist and Real Examples

User acceptance testing explained: who runs it, how it differs from QA, a seven-step process, a UAT test case template,…

Read article →
Artificial Intelligence

What Are Embeddings? Vectors and Cosine Similarity Explained Simply

What are embeddings? A plain-language guide to vectors, cosine similarity and semantic search, with a small example we ran, common…

Read article →
Test Automation

Flaky Tests: What Causes Them and How to Fix Them for Good

Flaky tests explained with demos we ran: the main causes, how to confirm and diagnose one, proper fixes for timing,…

Read article →
Software Testing

Load Testing vs Stress Testing: Differences, Metrics and k6 Examples

Load testing vs stress testing explained: what each proves, spike and soak tests, the metrics that matter, why averages mislead,…

Read article →