hurl
hurl copied to clipboard
Improving Assert Error for a given textual body
Response body can be tested directly without explicit asserts as follow:
test.hurl
1 GET http://example.com/text
2 HTTP/1.1 200
3 ```
4 one
5 two
6 three
7 ```
If the server returns the following response
one
to
three
the following error will be produced:
error: Assert Body Value
--> test.hurl:4:1
|
4 | one
| ^ actual value is <one
| to
| three>
Instead of taking into account the full multiline body, we could focus on the first line that differs.
The previous errors would become:
error: Assert Body Value
--> test.hurl:5:1
|
5 | two
| ^ actual value is <to>
|
This fits quite well with the line-oriented structure of hurl files.
Testing json output can also be a good example.
test.hurl
1 GET http://example.com/json
2 HTTP/1.1 200
3 {
4 "name": "Bob",
5 "age": 32
6 }
If the server returns the following response
{
"name": "Bob",
"age": 30
}
The following error will be produced:
error: Assert Body Value
--> test.hurl:3:1
|
3 | {
| ^ actual value is <{
| "user": "Bob"
| "age": "30"
| }>
Taking into account only the first line in error, we get the following error instead:
error: Assert Body Value
--> test.hurl:5:1
|
5 | "age": 32
| ^ actual value is < "age": 30>
|
We could even position the error at the exact different chracter
error: Assert Body Value
--> test.hurl:5:12
|
5 | "age": 32
| ^ actual value is <0>
|