hurl/docs/running-tests.md
2023-09-20 13:14:25 +00:00

117 lines
3.6 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Running Tests
## Use --test Option
Hurl is run by default as an HTTP client, returning the body of the last HTTP response.
```shell
$ hurl hello.hurl
Hello World!
```
When multiple input files are provided, Hurl outputs the body of the last HTTP response of each file.
```shell
$ hurl hello.hurl assert_json.hurl
Hello World![
{ "id": 1, "name": "Bob"},
{ "id": 2, "name": "Bill"}
]
```
For testing, we are only interested in the asserts results, we don't need the HTTP body response. To use Hurl as a
test tool with an adapted output, you can use [`--test` option]:
```shell
$ hurl --test hello.hurl assert_json.hurl
hello.hurl: Running [1/2]
hello.hurl: Success (6 request(s) in 245 ms)
assert_json.hurl: Running [2/2]
assert_json.hurl: Success (8 request(s) in 308 ms)
--------------------------------------------------------------------------------
Executed files: 2
Succeeded files: 2 (100.0%)
Failed files: 0 (0.0%)
Duration: 561 ms
```
Or, in case of errors:
```shell
$ hurl --test hello.hurl error_assert_status.hurl
hello.hurl: Running [1/2]
hello.hurl: Success (6 request(s) in 258 ms)
assert_json.hurl: Running [2/2]
error: Assert status code
--> assert_json.hurl:6:8
|
 6 | HTTP/* 200
| ^^^ actual value is <301>
|
assert_json.hurl: Failure (5 request(s) in 230 ms)
--------------------------------------------------------------------------------
Executed files: 2
Succeeded files: 1 (50.0%)
Failed files: 1 (50.0%)
Duration: 499 ms
```
You can use [`--glob` option] to test files that match a given pattern:
```shell
$ hurl --test --glob "test/integration/**/*.hurl"
```
## Generating Report
### HTML Report
Hurl can generate an HTML report by using the [`--report-html HTML_DIR`] option.
If the HTML report already exists, the test results will be appended to it.
<div class="picture">
<img class="u-drop-shadow u-border u-max-width-100" src="/docs/assets/img/hurl-html-report.png" width="670" alt="Hurl HTML Report">
</div>
The input Hurl files (HTML version) are also included and are easily accessed from the main page.
<div class="picture">
<img class="u-drop-shadow u-border u-max-width-100" src="/docs/assets/img/hurl-html-file.png" width="380" alt="Hurl HTML file">
</div>
### JUnit Report
A JUnit report can be produced by using the [`--report-junit FILE`] option.
If the JUnit report already exists, it will be updated with the new test results.
### TAP Report
A TAP report ([Test Anything Protocol]) can be produced by using the [`--report-tap FILE`] option.
If the TAP report already exists, it will be updated with the new test results.
## Use Variables in Tests
To use variables in your tests, you can:
- use [`--variable` option]
- use [`--variables-file` option]
- define environment variables, for instance `HURL_foo=bar`
You will find a detailed description in the [Injecting Variables] section of the docs.
[`--output /dev/null`]: /docs/manual.md#output
[`--test`]: /docs/manual.md#test
[`--report-html HTML_DIR`]: /docs/manual.md#report-html
[`--report-junit FILE`]: /docs/manual.md#report-junit
[`--report-tap FILE`]: /docs/manual.md#report-tap
[`--test` option]: /docs/manual.md#test
[`--glob` option]: /docs/manual.md#glob
[`--variable` option]: /docs/manual.md#variable
[`--variables-file` option]: /docs/manual.md#variables-file
[Injecting Variables]: /docs/templates.md#injecting-variables
[Test Anything Protocol]: https://testanything.org