Crate charted_testkit
source ·Expand description
§📦🦋 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.
Macros§
- Assertion macro to indicate that a
Responsedoesn’t have the header it needs. - Assertion macro to indicate that a
Responsehas the header it needs. - Macro to easily assert if a given response’s status code is the same as one you provide.
- Checks whenever if a
Responseis successful or not.
Structs§
Attribute Macros§
- Represents a procedural attribute macro that does the heavy lifting of
charted_testkitfor you. This macro also manages: