Tests

Tests let HTTPBot check a response for you automatically. Every time you tap Send, HTTPBot runs the request's tests against the response and reports which ones passed and which failed — so you can confirm an endpoint behaves the way you expect without eyeballing the output each time.

Results appear on the Tests tab of the response screen, with the actual value shown next to each assertion. See Viewing Responses.

You can add as many tests to a request as you need.

The response Tests tab showing a mix of passed and failed assertions.The response Tests tab showing a mix of passed and failed assertions.The response Tests tab showing a mix of passed and failed assertions.

Adding a test

  1. Open the request menu and choose Tests.
  2. Tap + to add a test.
  3. Choose a Test Type — what part of the response to look at.
  4. Choose a Comparator — how to compare it.
  5. Enter the expected value (when the comparator needs one).
  6. Save. The test now runs after every send.

You can edit or delete a test later from the same Tests list.

The test editor showing the Test Type, Comparator, and Expected Value fields.The test editor showing the Test Type, Comparator, and Expected Value fields.The test editor showing the Test Type, Comparator, and Expected Value fields.

Test types

Test Type What it checks
Status Code The HTTP status code (e.g. 200)
Response Time How long the request took, in ms or s
Response Size The response size, in bytes, KB, or MB
Response Body The raw response body text
Header A single header, selected by name
Headers The whole set of response headers (a list)
Cookie A single cookie, selected by name
Cookies The whole set of response cookies (a list)
JSON Path A value extracted from JSON via a JSONPath expression
JQ A value extracted from JSON via a jq filter expression (e.g. .user.id)
XPath A value extracted from XML/HTML via an XPath expression

For the Header and Cookie types you specify the name to look up. For JSON Path, JQ, and XPath you provide the path or filter expression that selects the value to test.

Server-Sent Events tests

When a response is a Server-Sent Events (SSE) stream, you can assert on the events it delivers:

Test Type What it checks
SSE Event Count How many events arrived
SSE Event Data The data payload of an event
SSE Event Name The event: name of an event
SSE Event JSON Path A JSONPath value inside an event's data

The data, name, and JSON Path SSE tests include an event selector that picks which event to look at: First, Last, By Index (you enter the index), By Name (you enter the event name), or Any. See Server-Sent Events for more on streaming responses.

Comparators

The comparators available depend on the test type. They fall into a few groups.

Equality and ordering (numeric types such as Status Code, Response Time, Response Size, and SSE Event Count):

Text matching (Response Body, Header, Cookie, JSON Path, JQ, XPath, and the SSE data/name tests):

List checks (the Headers and Cookies list types):

Case sensitivity

Text-based tests (Response Body, Header, Cookie, JSON Path, JQ, XPath, and the SSE data/name/JSON Path tests) offer a Case-Sensitive toggle so you can decide whether OK and ok should be treated as equal. For the Headers and Cookies list types, the toggle applies when you're checking for a specific key.

Examples

Reusing tests with the Test Library

If you've written a test you want to use again, you don't have to recreate it. From the test editor's menu, choose Select Existing Test to open the Test Library and pick a test you've created before. HTTPBot copies its type, comparator, and expected value into the test you're editing, which you can then tweak and save.

The Test Library list of previously created tests, grouped by typeThe Test Library list of previously created tests, grouped by typeThe Test Library list of previously created tests, grouped by type