Assertions & checks

The same condition types power two blocks with different consequences:

  • assert: — JMeter-style assertions. A failure marks the request failed (http_req_failed) and can change control flow via on_failure.
  • checks: — k6-style checks. Results are recorded into the checks rate metric (per-check, via the check tag) and never fail the request. Gate the run with a threshold: checks: ["rate>0.99"].
- request:
    url: /orders
    assert:
      - { type: status, equals: 201 }
      - { type: jsonpath, expression: "$.order.id", exists: true, on_failure: abort_iteration }
    checks:
      - { type: duration, name: fast enough, max: 250ms }
      - { type: body_contains, value: '"status":"pending"' }

Condition types

TypeFieldsPasses when
statusequals, one_of: [..], matches: "2.."status code matches
body_containsvalue, negatebody contains (or not) the substring
body_matchespattern, negatebody matches the regex
jsonpathexpression, equals, existsmatch exists (default) / equals the JSON value
xpathexpression, equals, existsXPath 1.0 result
durationmaxresponse duration ≤ max
sizemin, max, equalsbody size in bounds
headerheader, equals, contains, existsheader present/matching
jsexpressionthe JS expression is truthy (response is in scope)

All take an optional name (used in reports; a sensible one is generated otherwise) and, in assert: blocks, on_failure:

on_failureEffect
continue (default)record the failure, keep going
abort_iterationskip the rest of this iteration
abort_scenariostop this scenario
abort_teststop the whole run (exit code reflects failure)

JS conditions

checks:
  - type: js
    name: balanced response
    expression: "response.json ? true : JSON.parse(response.body).items.length > 0"

The response object has status, body, headers (lower-cased), duration_ms, url, error, protocol.