Expand description
Test client — fire HTTP requests against an axum::Router in tests
without binding a real socket. See test_client::TestClient.
Test client — fire HTTP requests against an axum::Router in tests
without binding a real socket.
§Quick start
ⓘ
use rustango::test_client::TestClient;
use axum::{Router, routing::get};
#[tokio::test]
async fn hello_endpoint_returns_200() {
let app = Router::new().route("/hello", get(|| async { "hi" }));
let client = TestClient::new(app);
let res = client.get("/hello").send().await;
assert_eq!(res.status, 200);
assert_eq!(res.text(), "hi");
}§JSON requests
ⓘ
let res = client
.post("/api/users")
.json(&serde_json::json!({"name": "Alice"}))
.send()
.await;
assert_eq!(res.status, 201);
let body: serde_json::Value = res.json();
assert_eq!(body["id"], 1);§Headers + cookies
ⓘ
let res = client
.get("/api/me")
.header("authorization", "Bearer eyJ...")
.send()
.await;Structs§
- Request
Builder - Builder for one outgoing test request.
- Test
Client - Test client wrapping an
axum::Router. - Test
Response - Captured response from a test request.