Expand description
§Axum Test Helper
This is a hard copy from TestClient at axum
§Features
cookies
- Enables support for cookies in the test client.withouttrace
- Disables tracing for the test client.
§Example
use axum::Router;
use axum::http::StatusCode;
use axum::routing::get;
use axum_test_helper::TestClient;
fn main() {
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("/").send().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§
- Request
Builder - Test
Client - Test
Response - A wrapper around
reqwest::Response
that provides common methods with internalunwrap()
s.