#test-containers #integration-tests #axum #service #assertions #hyper

charted-testkit

📦🦋 TestKit is a testing library for Axum services with testcontainers support

2 releases

0.1.1 Aug 20, 2024
0.1.0 Jun 23, 2024

#471 in Testing

Download history 1/week @ 2024-07-29 178/week @ 2024-08-19 54/week @ 2024-08-26 3/week @ 2024-09-02 13/week @ 2024-09-16 24/week @ 2024-09-23 20/week @ 2024-09-30 1/week @ 2024-10-07 74/week @ 2024-10-14 13/week @ 2024-10-21 13/week @ 2024-10-28 31/week @ 2024-11-04 17/week @ 2024-11-11

80 downloads per month
Used in charted-testkit-macros

MIT license

22KB
239 lines

Noel (Trans Heart)

📦🦋 charted TestKit

charted TestKit is a testing library for Axum, which extends libtest with its own test macro. The library can also be used for only Testcontainers as well.

TestKit was built to make integration testing easier for Axum services with Testcontainers support and additional macros to help build assertions based off Responses.

Example

use charted_testkit::{test, TestContext, assert_successful, consume_body};
use axum::{body::Bytes, routing, Router};
use hyper::Method;

async fn hello() -> &'static str {
    "Hello, world!"
}

fn router() -> Router {
    Router::new().route("/", routing::get(hello))
}

#[test(router)]
async fn mytest(ctx: TestContext) {
    let res = ctx
        .request("/", Method::GET, None::<axum::body::Bytes>, |_| {})
        .await
        .expect("unable to send request");

    assert_successful!(res);

    let body = consume_body!(res);
    assert_eq!(body, Bytes::from_static(b"Hello, world!"));
}

License

TestKit is released under the MIT License with love and care by Noelware, LLC.! 🐻‍❄️🦋

Please read the LICENSE file in the canonical repository for more information on what you can do with the source code.

Dependencies

~7–19MB
~266K SLoC