Assertions
Assertions validate API responses with powerful comparison operators. Failed assertions stop sequence execution and report detailed errors.
Basic Assertions
test sequence ValidateResponse
GET https://api.example.com/users/1
# Status checks
assert $1.status == 200
assert $1.status < 300
# Body value checks
assert $1.body.id == 1
assert $1.body.name == "Alice"
end sequence Comparison Operators
| Operator | Description | Example |
|---|---|---|
== | Equals | assert $1.status == 200 |
!= | Not equals | assert $1.body.count != 0 |
> | Greater than | assert $1.body.age > 18 |
>= | Greater or equal | assert $1.body.age >= 18 |
< | Less than | assert $1.body.count < 100 |
<= | Less or equal | assert $1.duration <= 5000 |
String Operators
assert $1.body.email contains "@"
assert $1.body.name startsWith "A"
assert $1.body.name endsWith "ice"
assert $1.body.email matches "[a-z]+@[a-z]+\.[a-z]+" String Literals and Escapes
Quoted strings decode escaped delimiters and escaped backslashes. Unknown backslash sequences are preserved as literal text, so Windows paths and values such as "Duration \Assertion" keep the backslash.
assert $1.body.message == "java.lang.NumberFormatException: For input string: \"{orderId}\""
assert $1.body.path == "C:\temp\orders.json"
assert $1.body.title == "Duration \Assertion" Use verbatim strings with @"..." when regexes or literal templates would otherwise need heavy escaping. In verbatim strings, backslashes are literal, doubled quotes become one quote, and {{...}} is not interpolated.
assert $1.body.message matches @"^java\.lang\.NumberFormatException: For input string: ""\{orderId\}""$"
assert rawTemplateText == @"{{expectedMessage}}" Schema Assertions
Validate a response body against a JSON Schema file. Contract assertions use the schema file name in run output and report how many schema properties or paths passed validation.
assert $1.body matchesSchema "./schemas/todo.schema.json" ✓ todo.schema.json: 4/4 validations passed When a contract fails, CLI output and VS Code Test Explorer show the contract name plus the most relevant validation issues instead of repeating the raw assertion expression.
Existence Checks
# Property must exist
assert $1.body.id exists
# Property must NOT exist
assert $1.body.deletedAt !exists Type Assertions
assert $1.body.id isType number
assert $1.body.name isType string
assert $1.body.active isType boolean
assert $1.body.tags isType array
assert $1.body.metadata isType object
assert $1.body.deletedAt isType null Timing Assertions
# Response must be fast
assert $1.duration < 2000 Custom Failure Messages
Add a custom message after the pipe:
assert $1.status == 200 | "API returned error status"
assert $1.body.id exists | "User ID was not returned" Array Assertions
# Access array elements
assert $1.body.users[0].name == "Alice"
# Check array length
assert $1.body.users.length > 0