Emphasize --test mode in tutorial.

This commit is contained in:
jcamiel 2022-06-11 12:49:24 +02:00 committed by jcamiel
parent 79c2f2b9be
commit e5d3cbe729
5 changed files with 69 additions and 147 deletions

View File

@ -63,47 +63,6 @@ You can use [`--glob` option] to test files that match a given patten:
$ hurl --test --glob "test/integration/**/*.hurl"
```
Finally, [`--test` option] is a shorthand over [`--output`], [`--progress`] and [`--summary`]:
- do not output response body ([`--output /dev/null`])
```shell
$ hurl --output /dev/null hello.hurl assert_json.hurl
```
- show progress ([`--progress`])
```shell
$ hurl --progress /dev/null hello.hurl assert_json.hurl
hello.hurl: RUNNING [1/2]
hello.hurl: SUCCESS
assert_json.hurl: RUNNING [2/2]
assert_json.hurl: SUCCESS
Hello World![
{ "id": 1, "name": "Bob"},
{ "id": 2, "name": "Bill"}
]
```
- print summary ([`--summary`])
```shell
$ hurl --summary hello.hurl assert_json.hurl
Hello World![
{ "id": 1, "name": "Bob"},
{ "id": 2, "name": "Bill"}
]
--------------------------------------------------------------------------------
Executed: 2
Succeeded: 2 (100.0%)
Failed: 0 (0.0%)
Duration: 134ms
```
These options can be combined or used independently depending on the use case.
## Generating an HTML Report
Hurl can also generate an HTML report by using the [`--report-html HTML_DIR`] option.
@ -128,13 +87,10 @@ To use variables in your tests, you can:
You will find a detail description in the [Injecting Variables] section of the doc.
[`--output /dev/null`]: /docs/man-page.md#output
[`--progress`]: /docs/man-page.md#progress
[`--summary`]: /docs/man-page.md#summary
[`--test`]: /docs/man-page.md#test
[`--report-html HTML_DIR`]: /docs/man-page.md#report-html
[`--test` option]: /docs/man-page.md#test
[`--glob` option]: /docs/man-page.md#glob
[`--output`]: /docs/man-page.md#output
[`--variable` option]: /docs/man-page.md#variable
[`--variables-file` option]: /docs/man-page.md#variables-file
[Injecting Variables]: /docs/templates.md#injecting-variables

View File

@ -10,6 +10,14 @@ GET https://example.org
$ hurl sample.hurl
```
By default, Hurl behaves like [curl] and outputs the last HTTP response's [entry]. To have a test
oriented output, you can use [`--test` option]:
```shell
$ hurl --test sample.hurl
```
You can check [Hurl tests suite] for more samples.
## Getting Data
@ -373,3 +381,6 @@ bytes startsWith hex,efbbbf;
[Hurl tests suite]: https://github.com/Orange-OpenSource/hurl/tree/master/integration/tests_ok
[Authorization]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization
[`-u/--user` option]: /docs/man-page.md#user
[curl]: https://curl.se
[entry]: /docs/entry.md
[`--test` option]: /docs/man-page.md#test

View File

@ -56,20 +56,17 @@ xpath "string(//head/title)" == "Welcome to Quiz!"
2. Run `basic.hurl`:
```shell
$ hurl basic.hurl
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Welcome to Quiz!</title>
<!-- <link rel="stylesheet" href="style.css">
<script src="script.js"></script>-->
</head>
....
</html>
$ hurl --test basic.hurl
basic.hurl: RUNNING [1/1]
basic.hurl: SUCCESS
--------------------------------------------------------------------------------
Executed: 1
Succeeded: 1 (100.0%)
Failed: 0 (0.0%)
Duration: 14ms
```
We get the content of the page and there is no error so everything is good!
There is no error so everything is good!
3. Modify the predicate value to "Welcome to Quaz!"
@ -86,7 +83,7 @@ xpath "string(//head/title)" == "Welcome to Quaz!"
4. Run `basic.hurl`:
```shell
$ hurl basic.hurl
$ hurl --test basic.hurl
error: Assert Failure
--> integration/basic.hurl:6:0
|
@ -145,17 +142,14 @@ xpath "string((//button)[2])" contains "Create"
3. Run `basic.hurl` and check that every assert has been successful:
```shell
$ hurl basic.hurl
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Welcome to Quiz!</title>
<!-- <link rel="stylesheet" href="style.css">
<script src="script.js"></script>-->
</head>
....
</html>
$ hurl --test basic.hurl
basic.hurl: RUNNING [1/1]
basic.hurl: SUCCESS
--------------------------------------------------------------------------------
Executed: 1
Succeeded: 1 (100.0%)
Failed: 0 (0.0%)
Duration: 14ms
```
@ -264,17 +258,14 @@ cookie "JSESSIONID[HttpOnly]" exists
5. Run `basic.hurl` and check that every assert has been successful:
```shell
$ hurl basic.hurl
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Welcome to Quiz!</title>
<!-- <link rel="stylesheet" href="style.css">
<script src="script.js"></script>-->
</head>
....
</html>
$ hurl --test basic.hurl
basic.hurl: RUNNING [1/1]
basic.hurl: SUCCESS
--------------------------------------------------------------------------------
Executed: 1
Succeeded: 1 (100.0%)
Failed: 0 (0.0%)
Duration: 16ms
```
## Performance Test

View File

@ -69,63 +69,6 @@ description.
2. Run `basic.hurl`:
```shell
$ hurl basic.hurl
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="/style.css">
<!--<script src="script.js"></script>-->
</head>
<body>
<div>
<img class="logo" src="/quiz.svg" alt="Quiz logo">
</div>
<h1>Error 404, Page not Found!</h1>
<a href="/">Quiz Home</a>
</body>
</html>
```
We can see that the test is still ok, but now, Hurl outputs the response of the last HTTP request (i.e.
the content of our 404 page). This is useful when you want to get data from a server, and you need to
perform additional steps (like login, confirmation etc...) before being able to call your last request.
In our tutorial, we're simply interested to verify the success or failure of our integration tests.
So, first, we'll remove the standard output (if a test is broken, we'll still have the error output).
3. Run `basic.hurl` while redirecting the standard ouput to `/dev/null`:
```shell
$ hurl basic.hurl > /dev/null
```
Then, we can also use [`--progress`] and [`--summary`] option to give us some feedback on
our tests progression and a simple summary:
4. Run `basic.hurl` with `--progress` and `--summary` options:
```shell
$ hurl --progress --summary basic.hurl > /dev/null
basic.hurl: RUNNING [1/1]
basic.hurl: SUCCESS
--------------------------------------------------------------------------------
Executed: 1
Succeeded: 1 (100.0%)
Failed: 0 (0.0%)
Duration: 40ms
```
Finally, we can use the [`--test`] option that is a shortcut for no output,
using [`--progress`] and [`--summary`] options:
5. Run `basic.hurl` with `--test` option:
```shell
$ hurl --test basic.hurl
basic.hurl: RUNNING [1/1]
@ -137,7 +80,8 @@ Failed: 0 (0.0%)
Duration: 40ms
```
From now on, we will always use `--test` to run our tests files.
We can see that the test is still ok, now two requests are ran in chain, and each response can be
tested independently.
## Test REST Api
@ -332,6 +276,4 @@ for your applications.
[JsonPath assert]: /docs/asserting-response.md#jsonpath-assert
[JsonPath query]: https://goessner.net/articles/JsonPath/
[query parameter section]: /docs/request.md#query-parameters
[`--progress`]: /docs/man-page.md#progress
[`--summary`]: /docs/man-page.md#summary
[`--test`]: /docs/man-page.md#test

View File

@ -73,7 +73,7 @@ typing the url <http://localhost:8080>:
Next, were going to write our first test.
1. Open a text editor and create a file named `basic.hurl`. In this file, just type the following text and save:</li>
1. Open a text editor and create a file named `basic.hurl`. In this file, just type the following text and save:
```hurl
GET http://localhost:8080
@ -85,7 +85,7 @@ This is your first Hurl file, and probably one of the simplest. It consists of o
> `GET` HTTP request on the endpoint <http://localhost:8080>. A request can be optionally followed by a [response
> description], to add asserts on the HTTP response. For the moment, we don't have any response description.
2. In a shell, execute `hurl` with `basic.hurl` as argument:</li>
2. In a shell, execute `hurl` with `basic.hurl` as argument:
```shell
$ hurl basic.hurl
@ -123,7 +123,7 @@ without checking the actual HTTP response.
As this test is not sufficient to ensure that our server is alive and running, we're going to add some asserts on
the response and, at least, check that the HTTP response status code is [`200 OK`].
3.Open `basic.hurl` and modify it to test the status code response:</li>
3. Open `basic.hurl` and modify it to test the status code response:
```hurl
GET http://localhost:8080
@ -147,20 +147,40 @@ $ hurl basic.hurl
```
There is no modification to the output of Hurl, the content of the HTTP request is outputted to the terminal. But, now,
we check that our server is responding with a `200 OK`.
we check that our server is responding with a `200 OK`.
5. Modify `basic.hurl` to test a different HTTP response status code:
By default, Hurl behaves like [curl] and outputs the HTTP response. This is useful when you want to get data from a
server, and you need to perform additional steps (like login, confirmation etc...) before being able to call your last
request.
In our case, we want to add tests to our project, so we can use [`--test`] command line option to have an adapted
test output:
5. Execute `basic.hurl` in test mode:
```shell
$ hurl --test basic.hurl
basic.hurl: RUNNING [1/1]
basic.hurl: SUCCESS
--------------------------------------------------------------------------------
Executed: 1
Succeeded: 1 (100.0%)
Failed: 0 (0.0%)
Duration: 14ms
```
6. Modify `basic.hurl` to test a different HTTP response status code:
```hurl
GET http://localhost:8080
HTTP/1.1 500
```
6. Save and execute it:
7. Save and execute it:
```shell
$ hurl basic.hurl
$ hurl --test basic.hurl
error: Assert Status
--> basic.hurl:2:10
|
@ -169,7 +189,7 @@ error: Assert Status
|
```
7. Revert your changes and finally add a comment at the beginning of the file:
8. Revert your changes and finally add a comment at the beginning of the file:
```hurl
@ -197,3 +217,5 @@ We're going to see in the next section how to improve our tests while keeping it
[response description]: /docs/response.md
[`500 Internal Server Error`]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500
[`200 OK`]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/200
[`--test`]: /docs/man-page.md#test
[curl]: https://curl.se