# hurl-test

Bibliothèque Rust qui exécute des scénarios Hurl sur une API depuis cargo test.

[HTML](https://hsjm.io/projects/hurl-test) · fr-FR

Rôle: Auteur

Type de projet: Bibliothèque Rust / tests HTTP

Équipe: Open source

2026

[Voir le projet](https://github.com/shorwood/hurl-test)

## Tests HTTP avec Hurl

hurl-test est une bibliothèque Rust qui exécute des scénarios Hurl depuis cargo test. Les tests envoient des requêtes HTTP à l’API et font échouer la suite si une assertion ne passe pas.

```hurl title="tests/hurl/notes_create_and_read.hurl — include développé"
POST {{base_url}}/notes
Content-Type: application/json
{
  "title": "  Buy milk  "
}
HTTP 201
# Reuse the server-assigned ID in the following requests.
[Captures]
note_id: jsonpath "$.id"
[Asserts]
jsonpath "$.id" > 0
jsonpath "$.title" == "Buy milk"

GET {{base_url}}/notes/{{note_id}}
HTTP 200
[Asserts]
jsonpath "$.id" == {{note_id}}
jsonpath "$.title" == "Buy milk"

GET {{base_url}}/notes
HTTP 200
[Asserts]
jsonpath "$" count >= 1
jsonpath "$[?(@.id == {{note_id}})].title" == "Buy milk"
```

## Lancer un serveur dans le test

L’exemple démarre le serveur sur un port disponible avant d’exécuter les scénarios. Le même test peut ainsi tourner localement ou dans un runner CI sans préparation manuelle du serveur.

```rust title="example/tests/hurl.rs"
use axum::serve;
use hurl_test::TestCases;
use miette::{IntoDiagnostic, Result};
use notes_api::app;
use tokio::{net::TcpListener, spawn};

// Hurl blocks this test's thread; another worker keeps the server responsive.
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn ui() -> Result<()> {
    let listener = TcpListener::bind("127.0.0.1:0").await.into_diagnostic()?;
    let address = listener.local_addr().into_diagnostic()?;
    // Dropping the test runtime stops the server, including after a test failure.
    spawn(async move { serve(listener, app()).await });

    TestCases::new()
        .variable("base_url", format!("http://{address}"))
        .ignore("tests/hurl/templates/**")?
        .include("tests/hurl/**/*.hurl")?
        .run()?;
    Ok(())
}
```

