Assertions
Assertions are used to validate the response returned by a request. In Axotly, assertions are declared using the EXPECT keyword followed by an expression that must evaluate to true.
If an assertion fails, the test is marked as failed and execution stops for that test.
How to Write Assertions
Syntax
EXPECT <expression>
Each EXPECT line represents a single assertion.
Assertion Targets
Assertions can be applied to:
status— the HTTP response status codebody— the parsed response body- Nested fields inside the body using dot notation
Examples
EXPECT status == 200
EXPECT body.id > 0
EXPECT body.user.name == "Axotly"
Comparison Assertions
Comparison assertions are used to compare values using standard comparison operators.
Supported Operators
== 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.id > 0
EXPECT body.age >= 18
in Operator
The in operator checks whether a value belongs to a list of allowed values.
Syntax
EXPECT <value> in (<item1>, <item2>, ...)
Example
EXPECT body.role in ("admin", "tester")
This assertion succeeds if body.role matches any value in the list.
between Operator
The between operator checks whether a numeric value falls within a specified range (inclusive).
Syntax
EXPECT <value> between <min> <max>
Example
EXPECT body.age between 18 99
This assertion succeeds if the value is greater than or equal to 18 and less than or equal to 99.
Field Existence Assertions
A field existence assertion verifies that a field is present in the response body.
Syntax
EXPECT <field>
Examples
EXPECT body.email
EXPECT body.created_at
These assertions succeed if the specified field exists in the response body, regardless of its value.
Nested Field Assertions
Fields inside objects can be accessed using dot notation.
Examples
EXPECT body.user.id > 0
EXPECT body.user.role in ("admin", "tester")
Assertion Evaluation Rules
- Assertions are evaluated in the order they appear
- If any assertion fails, the test fails
- Missing fields cause the assertion to fail (unless the assertion only checks for existence)
- Type mismatches result in assertion failure
Complete Example
EXPECT status == 200
EXPECT body.id > 0
EXPECT body.role in ("admin", "tester")
EXPECT body.age between 18 99
EXPECT body.email
EXPECT body.created_at
Summary
- Assertions validate response data
- All assertions start with the
EXPECTkeyword - Axotly supports:
- Comparison operators
- Membership checks (
in) - Range checks (
between) - Field existence validation
Clear and expressive assertions make tests easier to read and maintain.