25 releases
| new 0.1.443 | Mar 18, 2026 |
|---|---|
| 0.1.417 | Mar 10, 2026 |
| 0.1.397 | Feb 26, 2026 |
| 0.1.233 | Jan 30, 2026 |
#1443 in HTTP server
Used in rustapi-extras
1MB
17K
SLoC
rustapi-testing
Lens: "The Auditor"
Philosophy: "Trust, but verify."
A fluid, ergonomic test harness for RustAPI applications. Don't just test your logic; test your endpoints.
The TestClient
Integration testing is often painful. We make it easy. TestClient spawns your RustApi application without binding to a real TCP port, communicating directly with the service layer.
let client = TestClient::new(app);
Fluent Assertions
The client provides a fluent API for making requests and asserting responses.
client.post("/login")
.json(&credentials)
.send()
.await
.assert_status(200)
.assert_header("Set-Cookie", "session=...");
Mocking Services
Because rustapi-rs relies heavily on Dependency Injection via State<T>, you can easily inject mock implementations of your database or downstream services when creating the RustApi instance for your test.
Full Example
#[cfg(test)]
mod tests {
use rustapi_testing::TestClient;
use rustapi_rs::prelude::*;
#[tokio::test]
async fn test_create_user() {
// 1. Setup app
let app = RustApi::new().mount_route(create_user_route());
let client = TestClient::new(app);
// 2. Execute
let response = client.post("/users")
.json(&json!({ "name": "Alice" }))
.send()
.await;
// 3. Assert
response
.assert_status(StatusCode::OK)
.assert_json_path("$.id", 1);
}
}
Dependencies
~22–31MB
~549K SLoC