Assertions

Assertions allow you to validate API responses in a clear, readable way. They are written using the EXPECT keyword and are evaluated after a request is executed.

Assertions help you ensure:

  • The request succeeded
  • The response contains expected data
  • Values fall within valid ranges

Basic Syntax

Each assertion starts with the EXPECT keyword:

EXPECT <assertion>

Multiple assertions can be written one per line:

EXPECT status == 200
EXPECT body.name == "Axotly"
EXPECT body.role == "tester"

Paths

Paths are used to access values in the response.

Common paths include:

  • status – HTTP status code
  • `body. – Parsed.body
  • Nested fields using dot notation

Example:

EXPECT body.user.email

Binary Comparisons

Binary comparisons compare a value at a path with an expected value.

Supported Operators

Operator Meaning
== Equal to
!= Not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to

Examples

EXPECT status == 200
EXPECT body.age >= 18
EXPECT body.role != "admin"

Binary comparisons work with numbers, strings, and booleans.


in Operator

The in operator checks whether a value exists within a list of allowed values.

Syntax

EXPECT <path> in (<value1>, <value2>, ...)

Examples

EXPECT body.role in ("admin", "tester", "user")
EXPECT status in (200, 201, 204)

Use in when multiple outcomes are valid.


between Operator

The between operator checks whether a numeric value falls within a range (inclusive).

Syntax

EXPECT <path> between <min> <max>

Examples

EXPECT body.age between 18 65
EXPECT body.response_time between 100 500

This is useful for validating ranges such as ages, durations, and response times.


exists Operator

The exists operator checks that a path is present in the response.

Syntax

EXPECT exists <path>

Examples

EXPECT exists body.email
EXPECT exists body.metadata.request_id

This assertion does not validate the value itself—only that it exists.


Unary Path Assertions

Unary path assertions are a shorthand way to assert that a path exists and is not null.

Syntax

EXPECT <path>

Examples

EXPECT body.name
EXPECT body.profile.avatar

Unary assertions improve readability when you only care about presence.


Value Types

Assertions support the following value types:

Type Example
String "Axotly"
Number 42, 3.14
Bool true, false

Complete Example

EXPECT status == 200
EXPECT body.id > 0
EXPECT body.role in ("admin", "tester")
EXPECT body.age between 18 99
EXPECT exists body.email
EXPECT body.created_at

Cheatsheet

Common Assertions

EXPECT status == 200
EXPECT status != 500
EXPECT status in (200, 201, 204)
EXPECT body.name == "Axotly"
EXPECT body.age >= 18
EXPECT body.age between 18 65

Presence Checks

EXPECT exists body.email
EXPECT body.user.id
EXPECT body.profile.avatar

Comparison Operators

Operator Example
== EXPECT status == 200
!= EXPECT role != "admin"
> EXPECT age > 18
< EXPECT age < 65
>= EXPECT score >= 80
<= EXPECT score <= 100

in Operator

EXPECT status in (200, 201, 204)
EXPECT body.role in ("admin", "tester", "user")

between Operator

EXPECT body.age between 18 99
EXPECT body.response_time between 100 500

Value Types

EXPECT body.active == true
EXPECT body.count == 10
EXPECT body.name == "Axotly"

Full Example

EXPECT status == 200
EXPECT body.id > 0
EXPECT body.role in ("admin", "tester")
EXPECT body.age between 18 99
EXPECT exists body.email
EXPECT body.created_at

Summary

Assertion Type Purpose
Binary Compare values
in Match against multiple values
between Validate numeric ranges
exists Check field presence
Unary path Shorthand existence check