hurl/docs/running-tests.md
2022-06-11 16:27:12 +02:00

2.6 KiB

Running Tests

Use --test Option

Hurl is run by default as an HTTP client, returning the body of the last HTTP response.

$ hurl hello.hurl
Hello World!

When multiple input files are provided, Hurl outputs the body of the last HTTP response of each file.

$ 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:

$ hurl --test hello.hurl assert_json.hurl
hello.hurl: RUNNING [1/2]
hello.hurl: SUCCESS
assert_json.hurl: RUNNING [2/2]
assert_json.hurl: SUCCESS
--------------------------------------------------------------------------------
Executed:  2
Succeeded: 2 (100.0%)
Failed:    0 (0.0%)
Duration:  427ms

Or, in case of errors:

$ hurl --test hello.hurl error_assert_status.hurl 
hello.hurl: RUNNING [1/2]
hello.hurl: SUCCESS
error_assert_status.hurl: RUNNING [2/2]
error: Assert Status
  --> error_assert_status.hurl:2:10
   |
 2 | HTTP/1.0 200
   |          ^^^ actual value is <404>
   |

error_assert_status.hurl: FAILURE
-------------------------------------------------------------
Executed:  2
Succeeded: 1 (50.0%)
Failed:    1 (50.0%)
Duration:  52ms

You can use --glob option to test files that match a given patten:

$ hurl --test --glob "test/integration/**/*.hurl"

Generating an HTML Report

Hurl can also 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.

Hurl HTML Report

The input Hurl files (HTML version) are also included and are easily accessed from the main page.

Hurl HTML file

Use Variables in Tests

To use variables in your tests, you can:

You will find a detail description in the Injecting Variables section of the doc.