Skip to main content
Bruno uses the Chai library for assertions. All Chai expect syntax works in Bruno tests.
Write JavaScript test scripts to validate API responses, handle complex logic, and automate testing workflows. bru test script

Basic Test Structure

Common Test Examples

Testing Status Codes

Testing Response Body

Validating the JSON Body with jsonBody

Bruno provides a custom Chai assertion jsonBody to make response-body checks more readable. It’s the native Bruno equivalent of Postman’s pm.response.to.have.jsonBody(...), and supports four call shapes:
Negation is supported across all variants:
Migrating from Postman? When you import a Postman collection, Bruno automatically translates pm.response.to.have.jsonBody(...) (and pm.response.to.not.have.jsonBody(...)) into expect(res.getBody()).to.have.jsonBody(...). No manual rewriting needed.

Validating against a JSON Schema with jsonSchema

For contract testing, use the jsonSchema assertion to validate a response against a JSON Schema document. Bruno uses Ajv under the hood, so all modern JSON Schema drafts are supported (04, 06, 07, 2019-09, 2020-12) along with the full ajv-formats library.

Built-in formats

Common ajv-formats validators are available out of the box, including email, date, date-time, time, uri, uri-reference, uuid, ipv4, ipv6, hostname, and regex.

Passing Ajv options

You can pass any Ajv options as a second argument — useful, for example, to collect every validation error rather than failing on the first one:

Negation

Like jsonBody, the jsonSchema assertion runs in both the Safe Mode and the Developer Mode, and Postman’s pm.response.to.have.jsonSchema(schema) is automatically translated to expect(res.getBody()).to.have.jsonSchema(schema) on import.
Earlier versions of Bruno used tv4 for schema validation, which only supports JSON Schema draft-04. The new Ajv-based jsonSchema assertion is the recommended way to validate schemas going forward and supports drafts 04, 06, 07, 2019-09, and 2020-12.

Testing Nested Objects

Testing with Conditional Logic

Testing Arrays and Loops

Testing Response Headers

Testing Response Time

Advanced: Saving Values for Next Request

Error Handling

Common Chai Assertions

Next Steps

For more advanced scripting capabilities, see: