#test #http #e2e #end-to-end

grillon

Grillon offers an elegant and natural way to approach end-to-end HTTP API testing in Rust

3 releases (breaking)

Uses new Rust 2021

0.3.0 Jan 25, 2022
0.2.0 Jan 22, 2022
0.1.0 Dec 10, 2021

#317 in Testing

MIT/Apache

28KB
399 lines

Grillon

Crates.io docs.rs GitHub Workflow Status

Grillon offers an elegant and natural way to approach end-to-end HTTP API testing in Rust.

  • Elegant, intuitive and expressive API
  • Built-in testing functions
  • Extensible

Please note that the API is subject to a lot of changes until the v1.0.0.

Getting started

This example enables the optional diff feature and uses Tokio as asynchronous runtime. Generally, testing libs are used in unit or integration tests. You can declare grillon as a dev-dependency.

Add grillon to Cargo.toml

[dev-dependencies]
grillon = { version = "0.3.0", features = ["diff"] }
tokio = { version = "1", features = ["macros"] }

Then use grillon :

use grillon::{
    header::{HeaderValue, CONTENT_TYPE},
    json, Grillon, StatusCode, Result
};

#[tokio::test]
async fn end_to_end_test() -> Result<()> {
    Grillon::new("http://jsonplaceholder.typicode.com")?
        .post("posts")
        .payload(json!({
            "title": "foo",
            "body": "bar",
            "userId": 1
        }))
        .assert()
        .await
        .status_success()
        .assert_fn(|assert| {
            assert!(!assert.headers.is_empty());
            assert!(assert.status == StatusCode::CREATED);
            assert!(assert.json.is_some());

            println!("Json response : {:#?}", assert.json);
        })
        .status(StatusCode::CREATED)
        .headers_exist(vec![(
            CONTENT_TYPE,
            HeaderValue::from_static("application/json; charset=utf-8"),
        )])
        .body(json!({
            "id": 101,
        }));

    Ok(())
}

Dependencies

~9MB
~193K SLoC