Test by Design

Scenario suites in Postman, run by Newman

API suites written as scenarios: one ordered chain of requests per business flow, run in Postman and in CI with Newman.

A design note: the shape, when it is the right one, and what it costs.

One scenario, in order Collection runner or Newman, in CI request 1 pre · post request 2 pre · post request 3 pre · post request 4 pre · post request 5 pre · post setNextRequest() — loop, or branch One break request 1 pre · post request 2 pre · post request 3 fails here request 4 never runs request 5 never runs Each request needs what the one before it produced, so a failure in the middle is not one red test — it is every test after it.

Scroll sideways to see the whole diagram.

The opposite of the worker pool: here the order is the thing being tested.

What a scenario’s scripts do

Nothing hardcoded

Every value is generated at send time, including any signature the API expects.

Shared helpers

Kept in a collection variable, because Postman scripts cannot import files.

Data-driven runs

A CSV or JSON file turns one scenario into a table of cases.

Flow control

setNextRequest() for loops and branches — a jump that only works in the runner.

What those scripts look like

Sketches in Postman’s script API, written for this page to show the shape. They are not taken from a project.

Nothing hardcoded. A request’s pre-request script. The values are made at send time, from the run’s data file when it has one, and the signature is computed over exactly what is sent.
// Pre-request script: nothing in the request is typed in by hand.
const body = {
  invoiceNo: `INV-${Date.now()}`,
  // From the data file when the run has one: one row per case.
  amount: Number(pm.iterationData.get('amount')) || _.random(100, 5000),
}
pm.variables.set('body', JSON.stringify(body)) // the raw body is {{body}}

// The signature the API expects, over the bytes that are sent.
const signature = CryptoJS.HmacSHA256(
  pm.variables.get('body'),
  pm.environment.get('signingSecret'),
).toString(CryptoJS.enc.Base64)
pm.request.headers.upsert({ key: 'X-Signature', value: signature })
Shared helpers. Defined once in the collection, as text, and read back where a request needs them, since a script cannot import a file.
// Collection pre-request script: the helpers, kept as text.
pm.collectionVariables.set('helpers', `({
  expectStatus: (code) => pm.response.to.have.status(code),
  save: (name, path) =>
    pm.collectionVariables.set(name, _.get(pm.response.json(), path)),
})`)

// Any request's tests: read them back and use them.
const h = eval(pm.collectionVariables.get('helpers'))
h.expectStatus(200)
h.save('paymentToken', 'data.paymentToken') // for the next request
Flow control. Polling until a payment settles: the request runs itself again, up to a limit, then the flow goes on. In the runner and Newman only; sent by hand, it stops after one.
// Tests of "Inquire payment": ask again until it settles.
const status = pm.response.json().status
const tries = Number(pm.collectionVariables.get('tries') || 0) + 1
pm.collectionVariables.set('tries', tries)

if (status === 'PENDING' && tries < 5) {
  pm.execution.setNextRequest('Inquire payment') // this request again
} else {
  pm.collectionVariables.unset('tries')
  pm.test('the payment settles', () => pm.expect(status).to.eql('SUCCESS'))
}

When it is right, and what it costs

The cost
One broken request stops every request after it.
Why retries do not help
The failure is a broken precondition, not a flaky call. Retrying a request whose input is already wrong returns the same wrong answer.
When it is still right
When the flow is what is under test. Then the order is the point, not a cost.
The alternative
Tests that set up their own data and run side by side, as the suites on the front page do. The sequential shape still suits the flow tests.
Test by Design

© 2026 Surakiart Yasaka