Boundary value testing for APIs: the edges where validation breaks

A field accepts 1 to 100 characters. The happy-path test sends 20 and passes. The bug is at 0, 100 or 101: an empty name that gets stored, a 100-character name that the database truncates, a 101-character name that comes back as a 500 instead of a 400.

Boundary value testing means picking inputs at, just inside and just outside every limit. It's cheap to set up and finds a surprising share of validation bugs.

Write down the limits first

Take the endpoint's contract (an OpenAPI schema, the validation code, or the docs) and list each rule:

FieldRule
namestring, 1 to 100 characters
quantityinteger, 1 to 999
discountPercentnumber, 0 to 100
emailrequired, valid email

If you can't find a rule for a field, that is the first finding: nobody knows what the API accepts.

Turn the limits into cases

For name, that gives:

ValueWhyExpected
empty stringbelow minimum400
1 characterat minimum201
100 charactersat maximum201
101 charactersabove maximum400

Do the same for each numeric range: 0, 1, 999, 1000 for quantity; -1, 0, 100, 100.01 for discountPercent. Add one wrong type per field ("ten" for a number, [] for a string) and one missing required field.

One request, many rows

You don't need a request per case. Write one request with variables:

HTTP
POST {{baseUrl}}/orders
Content-Type: application/json

{"name": "{{name}}", "quantity": {{quantity}}, "discountPercent": {{discount}}, "email": "{{$randomEmail}}"}

Then a CSV with one row per case and the status you expect:

CSV
case,name,quantity,discount,expectedStatus
name at minimum,a,1,0,201
name empty,,1,0,400
quantity zero,Desk,0,0,400
quantity at maximum,Desk,999,0,201
quantity above maximum,Desk,1000,0,400
discount above 100,Desk,1,100.01,400
discount negative,Desk,1,-1,400

Long strings are awkward in a CSV, so build them in a pre-request script when the row asks for one:

JavaScript
// Pre-request: "name" can be "len:100" or "len:101"
const name = pm.iterationData.get('name') || '';
const m = /^len:(\d+)$/.exec(name);
if (m) pm.variables.set('name', 'x'.repeat(Number(m[1])));

Add rows name at maximum,len:100,1,0,201 and name too long,len:101,1,0,400.

The checks

JavaScript
const expected = Number(pm.iterationData.get('expectedStatus'));
const label = pm.iterationData.get('case');

pm.test(`${label}: status ${expected}`, () => {
  pm.response.to.have.status(expected);
});

pm.test(`${label}: never a server error`, () => {
  pm.expect(pm.response.code).to.be.below(500);
});

if (expected === 201) {
  pm.test(`${label}: value stored unchanged`, () => {
    pm.expect(pm.response.json().name).to.equal(pm.variables.get('name'));
  });
}

The last check catches silent truncation: the API answers 201 for 100 characters but stores 98 because a column is shorter than the validation rule.

Run it:

Terminal
requestarium run-collection "Orders API" --folder "Validation" --env Staging --data boundaries.csv

In the app, pick the same file under Iteration data in the collection runner. Each row is one iteration, named in the results by the case column you put in the test names.

What a good rejection looks like

A 400 alone isn't enough. A client developer needs to know which field failed and why:

JavaScript
if (expected === 400) {
  pm.test(`${label}: error names the field`, () => {
    const body = pm.response.text();
    pm.expect(body).to.match(/name|quantity|discount|email/);
  });
}

If your API uses a standard error shape such as application/problem+json, check its fields instead. See testing error responses for more.

Common findings

  • Off by one: < where the rule says <=, so the maximum itself is rejected.
  • Validation only on create: PATCH accepts what POST rejects. Run the same file against the update endpoint.
  • Numbers as strings: "5" is accepted for an integer field in one endpoint and rejected in another.
  • Unicode length: 100 emoji count as 100 characters in validation and 400 bytes in the database. See testing Unicode input.