Expand description
Axum Test Client
use axum::Router;
use axum::http::StatusCode;
use axum::routing::get;
use crate::servers::http::test_helpers::TestClient;
let async_block = async {
// you can replace this Router with your own app
let app = Router::new().route("/", get(|| async {}));
// initiate the TestClient with the previous declared Router
let client = TestClient::new(app);
let res = client.get("/").await;
assert_eq!(res.status(), StatusCode::OK);
};
// Create a runtime for executing the async block. This runtime is local
// to the main function and does not require any global setup.
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();
// Use the local runtime to block on the async block.
runtime.block_on(async_block);
Structsยง
- Builder for test requests.
- Test client to Axum servers.
- A wrapper around [
reqwest::Response
] that provides common methods with internalunwrap()
s.