Generates comprehensive tests for Axum handlers using generated types
Generates comprehensive test suites for Axum HTTP handlers using OpenAPI-generated types. Creates success, validation error, not found, conflict, and authorization test cases with helper functions and proper setup patterns.
/plugin marketplace add claude-market/marketplace/plugin install claude-market-specforge-backend-rust-axum-specforge-backend-rust-axum@claude-market/marketplacehaikuYou generate comprehensive tests for HTTP handlers using OpenAPI-generated types and test patterns.
Given:
Generate a complete test suite.
use axum::{
body::Body,
http::{Request, StatusCode},
};
use tower::ServiceExt;
use crate::generated::api::{CreateUserRequest, User, ErrorResponse};
mod common;
#[tokio::test]
async fn test_{handler_name}_success() {
// Setup
let db = common::setup_test_db().await;
let state = common::setup_test_state(db);
let app = create_router(state);
// Create request
let payload = CreateUserRequest {
email: "test@example.com".to_string(),
name: Some("Test User".to_string()),
};
let request = Request::builder()
.uri("/api/users")
.method("POST")
.header("content-type", "application/json")
.body(Body::from(serde_json::to_string(&payload).unwrap()))
.unwrap();
// Execute
let response = app.oneshot(request).await.unwrap();
// Assert
assert_eq!(response.status(), StatusCode::CREATED);
let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
let user: User = serde_json::from_slice(&body).unwrap();
assert_eq!(user.email, "test@example.com");
}
Generate tests for:
Create helper functions for common operations:
fn create_user_request(payload: &CreateUserRequest) -> Request<Body> {
Request::builder()
.uri("/api/users")
.method("POST")
.header("content-type", "application/json")
.body(Body::from(serde_json::to_string(payload).unwrap()))
.unwrap()
}
async fn parse_response_body<T: serde::de::DeserializeOwned>(response: Response) -> T {
let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
serde_json::from_slice(&body).unwrap()
}
rust-testing - Test patterns and setupaxum-patterns - Framework patternsrust-openapi-integration - Using generated types