Skip to main content
Bruno includes a comprehensive testing framework that allows you to write JavaScript test assertions to validate API responses. Tests are managed by the Tests component and use a Chai-based assertion library.

Overview

Tests in Bruno are JavaScript code snippets that run after receiving an API response. They use the same execution environment as scripts but are specifically designed for assertions and validations.

Tests vs Assertions

Bruno provides two ways to validate responses:
JavaScript test suite using Chai assertions. Managed by the Tests component.
Use the Assert tab for simple, declarative assertions. Use the Tests tab for complex validations, loops, and conditional logic.

Test Editor

The Tests component provides a CodeMirror editor with:
  • JavaScript syntax highlighting
  • Auto-hints for req, res, and bru objects
  • Keyboard shortcuts (Cmd/Ctrl+Enter to run, Cmd/Ctrl+S to save)
  • Error indicators in the Tests tab
From RequestPane/Tests/index.js:

Available Objects in Tests

object
Response object containing:
  • res.status: HTTP status code (e.g., 200, 404)
  • res.statusText: Status text (e.g., “OK”, “Not Found”)
  • res.headers: Response headers object
  • res.body: Parsed response body (JSON object/array)
  • res.getHeader(name): Get specific header value
  • res.getBody(): Get raw response body
object
Request object (read-only in tests):
  • req.url: Request URL
  • req.method: HTTP method
  • req.headers: Request headers
  • req.body: Request body
object
Bruno utility object:
  • bru.getVar(name): Get collection variable
  • bru.setVar(name, value): Set collection variable
  • bru.getEnvVar(name): Get environment variable
  • bru.setEnvVar(name, value): Set environment variable

Chai Assertion Library

Bruno tests use Chai for assertions. The expect and test functions are globally available.

Basic Assertions

Advanced Assertions

Real-World Examples

From the Bruno test suite:

Form URL Encoded Test

bruno-tests/collection/echo/echo form-url-encoded.bru

Collection-Level Test

From collection.bru:

Assert Combinations Test

From bruno-tests/collection/asserts/test-assert-combinations.bru showing various assertion patterns:

Common Testing Patterns

Test Storage

Tests are stored in the .bru file:
The Redux store manages test state through updateRequestTests action.

Test Execution & Results

When you send a request:
1

Request Executes

Bruno sends the HTTP request using the Axios client.
2

Response Received

Response data is captured and made available as res object.
3

Tests Run

Tests execute in order. Each test() function runs independently.
4

Results Displayed

Test results appear in the Response Pane, showing passed/failed tests.

Test Error Indicators

The Tests tab shows error indicators:
From HttpRequestPane component
Failed tests populate item.testScriptErrorMessage.

Collection Runner Tests

When running multiple requests using the RunCollectionItem component, tests run for each request and results are aggregated in RunnerResults.

Best Practices

Use clear, descriptive names that explain what is being tested:
Keep tests focused on a single assertion or related group:
Choose the right Chai assertion for readability:
Test happy paths and error scenarios:
Put repeated validations in collection-level tests:
collection.bru tests

Next Steps

Assertions

Learn about inline assertions using the Assert tab

Scripts

Combine tests with pre/post-request scripts

Collection Runner

Run tests across multiple requests

Collection Settings

Configure collection-level tests