### Run Specific Example Tests Source: https://github.com/josephlenton/axum-test/blob/main/CLAUDE.md Execute tests for a particular example. Use the --features flag to enable specific feature sets required by the example. ```bash cargo +stable test --example=todo ``` ```bash cargo +stable test --example=snapshots --features yaml ``` ```bash cargo +stable test --example=websocket-ping-pong --features ws ``` ```bash cargo +stable test --example=websocket-chat --features ws ``` -------------------------------- ### Run Axum Example with YAML Feature Source: https://github.com/josephlenton/axum-test/blob/main/examples/snapshots/README.md Run the Axum example application, enabling the 'yaml' feature for YAML response handling. ```bash cargo run --example=snapshots --features yaml ``` -------------------------------- ### Run All Tests with Make Source: https://github.com/josephlenton/axum-test/blob/main/CLAUDE.md Execute the full test suite, mirroring the Continuous Integration environment. This includes check, examples, feature combinations, clippy, and MSRV checks. ```bash make test ``` -------------------------------- ### Run Doc Tests Source: https://github.com/josephlenton/axum-test/blob/main/CLAUDE.md Execute documentation tests with all features enabled to ensure examples in documentation are correct. ```bash cargo +stable test --features all --doc ``` -------------------------------- ### Rust Unit Test Example Source: https://github.com/josephlenton/axum-test/blob/main/CLAUDE.md Illustrates the standard pattern for writing unit tests within a Rust source file. Tests are placed in `#[cfg(test)]` modules and use `#[tokio::test]` for asynchronous tests. ```rust #[cfg(test)] mod test_fmt { use super::*; #[test] fn it_should_format_range() { let output = StatusCodeRangeFormatter(StatusCode::OK..StatusCode::IM_USED).to_string(); assert_eq!(output, "200..226"); } } ``` -------------------------------- ### Basic Ping-Pong Test Source: https://github.com/josephlenton/axum-test/blob/main/README.md Demonstrates a simple end-to-end test for an Axum application. It sets up a basic router, runs it with TestServer, sends a GET request, and asserts the status and response body. ```rust use axum::Router; use axum::routing::get; use axum_test::TestServer; #[tokio::test] async fn it_should_ping_pong() { // Build an application with a route. let app = Router::new() .route(&"/ping", get(|| async { "pong!" })); // Run the application for testing. let server = TestServer::new(app); // Get the request. let response = server .get("/ping") .await; // Assert! response .assert_status_ok() .assert_text("pong!"); } ``` -------------------------------- ### Build Documentation Source: https://github.com/josephlenton/axum-test/blob/main/CLAUDE.md Generate and open the project's documentation in a web browser, including all features. ```bash cargo doc --open --features all ``` -------------------------------- ### Run Quick Tests Source: https://github.com/josephlenton/axum-test/blob/main/CLAUDE.md Execute tests with default features enabled using the stable toolchain. ```bash cargo +stable test ``` -------------------------------- ### Run Tests with All Features Source: https://github.com/josephlenton/axum-test/blob/main/CLAUDE.md Execute all tests, including those enabled by all feature flags. ```bash cargo +stable test --features all ``` -------------------------------- ### Run Tests with YAML Feature Source: https://github.com/josephlenton/axum-test/blob/main/examples/snapshots/README.md Execute the snapshot tests for the Axum application, ensuring the 'yaml' feature is enabled. ```bash cargo test --example=snapshots --features yaml ``` -------------------------------- ### Lint Code with Clippy Source: https://github.com/josephlenton/axum-test/blob/main/CLAUDE.md Run Clippy with the stable toolchain to check for common mistakes and enforce code quality. ```bash cargo +stable clippy ``` -------------------------------- ### Format Code with Cargo Source: https://github.com/josephlenton/axum-test/blob/main/CLAUDE.md Use this command to format all Rust code within the project according to standard conventions. ```bash cargo fmt ``` -------------------------------- ### Conditional Compilation with Features Source: https://github.com/josephlenton/axum-test/blob/main/CLAUDE.md Use this attribute to gate code that should only be compiled when a specific feature flag is enabled. ```rust #[cfg(feature = "my-feature")] ``` -------------------------------- ### Asserting JSON Shape with Axum Test Source: https://github.com/josephlenton/axum-test/blob/main/README.md Use `assert_json` with `expect_json` matchers to validate the structure and specific values of JSON responses. This is useful for ensuring API consistency without needing to match the entire JSON payload exactly. ```rust use axum_test::TestServer; use axum_test::expect_json; use std::time::Duration; // Your application let app = Router::new() .route(&"/user/alan", get(|| async { // ... })); let server = TestServer::new(app); server.get(&"/user/alan") .await .assert_json(&json!({ "name": "Alan", // expect a valid UUID "id": expect_json::uuid(), // expect an adult age "age": expect_json::integer() .in_range(18..=120), // expect user to be created within the last minute "created_at": expect_json::iso_date_time תחתונה .within_past(Duration::from_secs(60)) .utc() })); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.