### Basic usage with AllureFacade and lifecycle Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-rust-commons/README.md Creates a FileSystemResultsWriter, initializes AllureRuntime, and uses the lifecycle facade to start and end a test with attachments and parameters. ```rust use allure_rust_commons::{AllureFacade, AllureRuntime, FileSystemResultsWriter, Status}; fn main() -> Result<(), Box> { let writer = FileSystemResultsWriter::new("target/allure-results")?; let runtime = AllureRuntime::new(writer); let lifecycle = runtime.lifecycle(); let allure = AllureFacade::with_lifecycle(lifecycle); allure.start_test_with_full_name("login_works", "auth::login_works"); allure.feature("Authentication"); allure.parameter("browser", "firefox"); allure.stage("open login page"); allure.log_step("open login page"); allure.attachment("request.json", "application/json", br#"{"ok":true}"#); allure.end_test(Status::Passed, None); Ok(()) } ``` -------------------------------- ### Minimal Allure integration sketch with AllureRuntime and lifecycle Source: https://github.com/allure-framework/allure-rust/blob/main/README.md Initializes a FileSystemResultsWriter and AllureRuntime, then starts and stops a test case with the lifecycle. Use this as a starting point for integrating Allure with another Rust test runner or framework. The writer writes results to 'target/allure-results'. ```rust use allure_rust_commons::{AllureRuntime, FileSystemResultsWriter, Status}; let writer = FileSystemResultsWriter::new("target/allure-results")?; let runtime = AllureRuntime::new(writer); let lifecycle = runtime.lifecycle(); lifecycle.start_test_case( allure_rust_commons::StartTestCaseParams::new("my test").with_full_name("suite::my test") ); // ... update metadata, steps, and attachments during execution ... lifecycle.stop_test_case(Status::Passed, None); ``` -------------------------------- ### Runtime facade functions Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-rust-commons/README.md Framework-neutral helpers for common Allure concepts, including metadata, labels, parameters, steps, evidence, and run-level diagnostics. ```APIDOC ## Runtime facade functions ### Description Framework-neutral helpers for common Allure concepts, including metadata, labels, parameters, steps, evidence, and run-level diagnostics. ### Functions - **Metadata**: `display_name`, `description`, `description_html`, `history_id`, `test_case_id`, `id`, `allure_id` - **Labels and links**: `label`, `labels`, `epic`, `feature`, `story`, `suite`, `parent_suite`, `sub_suite`, `owner`, `severity`, `tag`, `tags`, `link`, `links`, `issue`, `tms` - **Parameters**: `parameter`, `parameter_excluded`, `parameter_mode`, `parameter_with_options` - **Steps**: `log_step`, `log_step_with`, `step`, `stage` - **Evidence**: `attachment`, `attachment_path`, `attach_trace`, `http_exchange`, `http_exchange_named` - **Run-level diagnostics**: `global_attachment`, `global_attachment_path`, `global_error`, `global_error_with_trace`, `report_global_error` ``` -------------------------------- ### Add allure-diesel as a dev dependency Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-diesel/README.md Install the crate with cargo add. Use the --dev flag to add it as a development dependency. ```bash cargo add allure-diesel --dev ``` -------------------------------- ### Report global setup failure with GlobalError Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-rust-commons/README.md Report a final failure outside any concrete test case, such as during global setup, using report_global_error with GlobalError. The convenience methods add the observation timestamp automatically; this preserves structured assertion evidence or a runner-supplied event timestamp. ```rust use allure_rust_commons::{AllureFacade, GlobalError}; fn report_setup_failure(allure: &AllureFacade) -> std::io::Result<()> { allure.report_global_error( GlobalError::new("Global setup failed: expected and actual environments differed") .with_trace("AssertionError: environment mismatch\n at global_setup") .with_actual("staging") .with_expected("test"), ) } ``` -------------------------------- ### reporter::http_exchange Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-rust-commons/README.md Records an HTTP exchange from adapter code with exact active-owner placement. ```APIDOC ## reporter::http_exchange ### Description Records an HTTP exchange from adapter code with exact active-owner placement. ### Usage ```rust use allure_rust_commons::{reporter, AllureFacade, HttpExchange}; fn attach_from_adapter(allure: &AllureFacade) { reporter::http_exchange(allure, HttpExchange::new("GET", "https://example.invalid")); } ``` ### Parameters - **allure** (AllureFacade) - Required - The Allure facade instance. - **exchange** (HttpExchange) - Required - The HTTP exchange to record. ``` -------------------------------- ### Global wiring with install_default Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-diesel/README.md Registers the instrumentation for every newly established connection in the process. Call it once during test setup so connections created by the code under test are captured with no call-site changes. ```rust fn setup() -> diesel::QueryResult<()> { allure_diesel::install_default() } ``` -------------------------------- ### Attach HTTP exchange with HttpExchange Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-rust-commons/README.md Use HttpExchange to capture request/response evidence for Allure viewers or API coverage tools. The example creates an exchange for a POST request, sets the request body with content type, encoding, value, size, and truncated flag, and sets the response status and status text before attaching it via allure.http_exchange(). ```rust use allure_rust_commons::{ AllureFacade, HttpExchange, HttpExchangeBody, HttpExchangeBodyEncoding, HttpExchangeResponse, }; fn attach_order_exchange(allure: &AllureFacade) { let mut exchange = HttpExchange::new("POST", "https://api.example.com/v1/orders"); exchange.request.body = Some(HttpExchangeBody { content_type: Some("application/json".to_string()), encoding: Some(HttpExchangeBodyEncoding::Utf8), value: Some(r#"{"name":"demo"}"#.to_string()), size: Some(15), truncated: Some(false), ..Default::default() }); exchange.response = Some(HttpExchangeResponse { status: Some(201), status_text: Some("Created".to_string()), ..Default::default() }); allure.http_exchange(exchange); } ``` -------------------------------- ### reporter::attachment Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-rust-commons/README.md Attaches an attachment from adapter code with exact active-owner placement. ```APIDOC ## reporter::attachment ### Description Attaches an attachment from adapter code with exact active-owner placement. ### Usage ```rust use allure_rust_commons::{reporter, AllureFacade}; fn attach_from_adapter(allure: &AllureFacade) { reporter::attachment(allure, "trace.txt", "text/plain", "raw trace"); } ``` ### Parameters - **allure** (AllureFacade) - Required - The Allure facade instance. - **name** (string) - Required - The attachment name. - **content_type** (string) - Required - The MIME type of the attachment. - **content** (string) - Required - The attachment content. ``` -------------------------------- ### Configure capture options with CaptureOptions Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-diesel/README.md Customize what is captured: disable transaction recording, enable connection events, omit SQL attachments, or truncate the SQL preview in step names. The example shows all available options. ```rust use allure_diesel::{AllureInstrumentation, CaptureOptions}; let options = CaptureOptions::default() .without_transactions() // don't record transaction boundaries .with_connection_events() // record connection establishment (off by default) .without_sql_attachment() // keep the SQL in the step name only .with_max_sql_preview(256); // truncate the SQL used in step names let instrumentation = AllureInstrumentation::with_options(options); ``` -------------------------------- ### Match source file or directory for labels Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-cargotest/README.md Use path to match a source file or directory. Directory form matches every test file whose relative path starts with that directory. ```toml [[package.metadata.allure.modules]] path = "src/payments.rs" labels = { component = "payments" } ``` ```toml [[package.metadata.allure.modules]] path = "tests/api/" labels = { layer = "api" } ``` -------------------------------- ### allure::test_with_async Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-rust-commons/README.md Wraps an async Rust #[test] function with explicit TestOptions for metadata. ```APIDOC ## allure::test_with_async ### Description Wraps an async Rust #[test] function with explicit TestOptions for metadata. ### Usage ```rust allure::test_with_async(TestOptions::new(...), || async { ... }); ``` ### Parameters - **options** (TestOptions) - Required - Configuration for the test metadata. - **closure** (FnOnce) - Required - The async test body to execute and report. ``` -------------------------------- ### Reporter module attachment and HTTP exchange Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-rust-commons/README.md Use the reporter module for exact active-owner attachment placement from adapter internals. Runtime attachment and HTTP exchange helpers create an ordered evidence step by default, but this approach bypasses that. ```rust use allure_rust_commons::{reporter, AllureFacade, HttpExchange}; fn attach_from_adapter(allure: &AllureFacade) { reporter::attachment(allure, "trace.txt", "text/plain", "raw trace"); reporter::http_exchange(allure, HttpExchange::new("GET", "https://example.invalid")); } ``` -------------------------------- ### allure::test_async Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-rust-commons/README.md Wraps an async Rust #[test] function to report Allure test results. ```APIDOC ## allure::test_async ### Description Wraps an async Rust #[test] function to report Allure test results. ### Usage ```rust allure::test_async(|| async { ... }); ``` ### Parameters - **closure** (FnOnce) - Required - The async test body to execute and report. ``` -------------------------------- ### Generate and open Allure 3 report Source: https://github.com/allure-framework/allure-rust/blob/main/README.md Uses the Allure 3 CLI to generate a report from result files and open it. Requires *-result.json files in the results directory. If installed via Node, use the equivalent npx command. ```bash allure generate ./target/allure-results --output ./target/allure-report --clean ``` ```bash allure open ./target/allure-report ``` -------------------------------- ### Create FileSystemResultsWriter with target directory Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-rust-commons/README.md Creates a results writer for the specified directory. The directory is created if it does not exist. Results are written atomically with a .tmp suffix before being renamed. ```rust let writer = FileSystemResultsWriter::new("target/allure-results")?; ``` -------------------------------- ### AllureFacade::report_global_error Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-rust-commons/README.md Reports a global error outside any test case, for example during discovery, global setup, container initialization, or global teardown. ```APIDOC ## AllureFacade::report_global_error ### Description Reports a global error outside any test case, for example during discovery, global setup, container initialization, or global teardown. ### Usage ```rust use allure_rust_commons::{AllureFacade, GlobalError}; fn report_setup_failure(allure: &AllureFacade) -> std::io::Result<()> { allure.report_global_error( GlobalError::new("Global setup failed: expected and actual environments differed") .with_trace("AssertionError: environment mismatch\n at global_setup") .with_actual("staging") .with_expected("test"), ) } ``` ### Parameters - **error** (GlobalError) - Required - The global error to report. ### Returns - **Result<()>** - Indicates success or failure of the operation. ``` -------------------------------- ### Macro-free cargo test with allure::test Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-rust-commons/README.md Wrap a regular Rust #[test] with allure::test when attribute macros are not allowed. The test name is inferred from the current cargo-test thread, and the closure gets the same thread-bound runtime context used by the convenience functions. ```rust use allure_rust_commons as allure; #[test] fn login_works() { allure::test(|| { allure::feature("Authentication"); allure::parameter("browser", "firefox"); allure::stage("prepare data"); let user = "alice"; allure::stage("submit credentials"); allure::step("send request", || { allure::attachment("request.json", "application/json", br#"{"user":"alice"}"#); }); allure::stage("verify result"); assert_eq!(user, "alice"); }); } ``` -------------------------------- ### Add labels for integration test modules Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-cargotest/README.md For integration tests in tests/api.rs, module paths usually start with the file stem. Use this configuration to apply labels. ```toml [[package.metadata.allure.modules]] module = "api::org::example" labels = { a = "a-value" } ``` -------------------------------- ### Basic usage with #[allure_test] and #[step] Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-cargotest/README.md Annotate tests with #[allure_test] and helper functions with #[step]. Results are written to target/allure-results by default. The example shows using free functions like feature, parameter, stage, log_step, and attachment. ```rust use allure_cargotest::{allure_test, step}; use allure_rust_commons::{attachment, feature, log_step, parameter, stage}; #[step] fn open_login_page() { // your step implementation } /// Verifies a user can open the login page and collect debug evidence. #[allure_test] #[test] fn login_works() { feature("Authentication"); parameter("browser", "firefox"); stage("open login page"); open_login_page(); log_step("login page opened"); stage("collect evidence"); attachment("page.html", "text/html", "..."); } ``` -------------------------------- ### allure::test_with Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-rust-commons/README.md Wraps a regular Rust #[test] function with explicit TestOptions for metadata such as full name, title path, manifest dir, module path, labels, or IDs. ```APIDOC ## allure::test_with ### Description Wraps a regular Rust #[test] function with explicit TestOptions for metadata such as full name, title path, manifest dir, module path, labels, or IDs. ### Usage ```rust allure::test_with(TestOptions::new(...), || { ... }); ``` ### Parameters - **options** (TestOptions) - Required - Configuration for the test metadata. - **closure** (FnOnce) - Required - The test body to execute and report. ``` -------------------------------- ### allure::test_with_outcome_async Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-rust-commons/README.md Wraps an async Rust #[test] function with outcome handling, reporting values implementing AllureTestOutcome. ```APIDOC ## allure::test_with_outcome_async ### Description Wraps an async Rust #[test] function with outcome handling, reporting values implementing AllureTestOutcome. ### Usage ```rust allure::test_with_outcome_async(|| async { ... }); ``` ### Parameters - **closure** (FnOnce) - Required - The async test body to execute and report. ``` -------------------------------- ### allure::test_named_async Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-rust-commons/README.md Wraps an async Rust #[test] function with a custom display name for Allure reporting. ```APIDOC ## allure::test_named_async ### Description Wraps an async Rust #[test] function with a custom display name for Allure reporting. ### Usage ```rust allure::test_named_async("Custom test name", || async { ... }); ``` ### Parameters - **name** (string) - Required - The custom display name for the test. - **closure** (FnOnce) - Required - The async test body to execute and report. ``` -------------------------------- ### allure::test_with_outcome Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-rust-commons/README.md Wraps a regular Rust #[test] function with outcome handling, reporting values implementing AllureTestOutcome. ```APIDOC ## allure::test_with_outcome ### Description Wraps a regular Rust #[test] function with outcome handling, reporting values implementing AllureTestOutcome. ### Usage ```rust allure::test_with_outcome(|| { ... }); ``` ### Parameters - **closure** (FnOnce) - Required - The test body to execute and report. ``` -------------------------------- ### allure::test_named Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-rust-commons/README.md Wraps a regular Rust #[test] function with a custom display name for Allure reporting. ```APIDOC ## allure::test_named ### Description Wraps a regular Rust #[test] function with a custom display name for Allure reporting. ### Usage ```rust allure::test_named("Custom test name", || { ... }); ``` ### Parameters - **name** (string) - Required - The custom display name for the test. - **closure** (FnOnce) - Required - The test body to execute and report. ``` -------------------------------- ### Use re-exported macros with #[allure_test], #[step], and #[log_asserts] Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-test-macros/README.md Shows the recommended usage of the re-exported macros. #[step] records a function call as an Allure step, #[log_asserts] rewrites standard assertion macros for logging, and #[allure_test] wraps a #[test] function with Allure lifecycle setup and teardown. Rust doc comments on #[allure_test] functions are used as the default markdown description. ```rust use allure_cargotest::{allure_test, log_asserts, step}; #[step(name = "Open login page")] fn open_login_page() {} #[log_asserts] fn check_login_state() { assert!(true); } /// Confirms the login check records a page-opening step and assertion evidence. #[allure_test(name = "Login works", id = "AUTH-1")] #[test] fn login_works() { open_login_page(); check_login_state(); } ``` -------------------------------- ### Thread-bound convenience functions with push_current_allure Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-rust-commons/README.md Binds an AllureFacade to the current thread using push_current_allure, then uses framework-neutral functions like feature, parameter, stage, and log_step without passing the facade. ```rust use allure_rust_commons::{ feature, log_step, parameter, push_current_allure, stage, AllureFacade, AllureRuntime, FileSystemResultsWriter, Status, }; fn main() -> Result<(), Box> { let writer = FileSystemResultsWriter::new("target/allure-results")?; let runtime = AllureRuntime::new(writer); let allure = AllureFacade::with_lifecycle(runtime.lifecycle()); allure.start_test_with_full_name("login_works", "auth::login_works"); let _current = push_current_allure(&allure); feature("Authentication"); parameter("browser", "firefox"); stage("open login page"); log_step("open login page"); allure.end_test(Status::Passed, None); Ok(()) } ``` -------------------------------- ### Configure CaptureOptions for response body capture Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-reqwest/README.md By default, the integration captures method, URL, query, headers, status, timing, and transport errors. In-memory request bodies are captured up to a bounded size; response body capture is opt-in. This example enables response body capture with a 64 KiB limit. ```rust use allure_reqwest::{AllureReqwestClient, CaptureOptions}; let client = AllureReqwestClient::new(allure).with_options( CaptureOptions::default().with_response_body_capture(64 * 1024), ); ``` -------------------------------- ### Runtime wrapper without attribute macros Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-cargotest/README.md Use the commons runtime wrapper directly when attribute macros are not allowed. The example shows calling allure::test with a closure that uses feature, stage, and log_step. ```rust use allure_rust_commons as allure; #[test] fn login_works() { allure::test(|| { allure::feature("Authentication"); allure::stage("open login page"); allure::log_step("open login page"); }); } ``` -------------------------------- ### allure::test Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-rust-commons/README.md Wraps a regular Rust #[test] function to report Allure test results. The test name is inferred from the current cargo-test thread, and the closure receives the thread-bound runtime context. ```APIDOC ## allure::test ### Description Wraps a regular Rust #[test] function to report Allure test results. The test name is inferred from the current cargo-test thread, and the closure receives the thread-bound runtime context. ### Usage ```rust use allure_rust_commons as allure; #[test] fn login_works() { allure::test(|| { allure::feature("Authentication"); allure::parameter("browser", "firefox"); allure::stage("prepare data"); let user = "alice"; allure::stage("submit credentials"); allure::step("send request", || { allure::attachment("request.json", "application/json", br#"{"user":"alice"}"#); }); allure::stage("verify result"); assert_eq!(user, "alice"); }); } ``` ### Parameters - **closure** (FnOnce) - Required - The test body to execute and report. ``` -------------------------------- ### Add allure-rust-commons for custom adapters Source: https://github.com/allure-framework/allure-rust/blob/main/README.md Adds the allure-rust-commons crate for building custom integration or framework adapters. ```bash cargo add allure-rust-commons ``` -------------------------------- ### Package run profile: allure agent with cargo test -p Source: https://github.com/allure-framework/allure-rust/blob/main/docs/allure-test-agent.md Focused crate validation. Choose the package and expectation controls for the touched scope. Use a temporary results directory via ALLURE_RESULTS_DIR. ```bash TMP_DIR="$(mktemp -d)" && ALLURE_RESULTS_DIR="$TMP_DIR/allure-results" allure agent --goal "" -- cargo test -p --all-targets ``` -------------------------------- ### Add allure-rust-commons as dev dependency Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-cargotest/README.md Run this command to also add the framework-neutral convenience functions crate as a development dependency. ```bash cargo add allure-rust-commons --dev ``` -------------------------------- ### Reqwest middleware run profile: allure agent with --features middleware Source: https://github.com/allure-framework/allure-rust/blob/main/docs/allure-test-agent.md Validates the optional middleware integration. Only covers the middleware feature profile plus default reqwest tests. Use a temporary results directory via ALLURE_RESULTS_DIR. ```bash TMP_DIR="$(mktemp -d)" && ALLURE_RESULTS_DIR="$TMP_DIR/allure-results" allure agent --goal "" -- cargo test -p allure-reqwest --all-targets --features middleware ``` -------------------------------- ### Using #[allure_test] and #[step] attributes Source: https://github.com/allure-framework/allure-rust/blob/main/README.md Initializes a reporter automatically using ALLURE_RESULTS_DIR or target/allure-results and wraps the test lifecycle. Supports ordinary () tests and explicit return types implementing std::process::Termination, including Result<(), E>, ExitCode, and custom termination types. Returned Err values and unsuccessful ExitCode values are written to Allure before Cargo interprets the result. ```rust use allure_cargotest::{allure_test, step}; use allure_rust_commons::{feature, log_step, parameter, stage}; #[allure_test] #[test] fn test_with_allure() { feature("Authentication"); parameter("browser", "firefox"); stage("open login page"); open_login_page(); log_step("login page opened"); } #[step] fn open_login_page() { // your step implementation } ``` -------------------------------- ### Run only matching tests with ALLURE_TESTPLAN_PATH Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-cargotest/README.md Set ALLURE_TESTPLAN_PATH to an Allure test-plan JSON file to run only matching test identities. The adapter loads the plan once for a macro-driven test process and once when a manual CargoTestReporter is created. If the file cannot be read or parsed, selection is not applied, tests remain runnable, and the initialization failure is written as its own *-globals.json artifact. ```bash ALLURE_TESTPLAN_PATH=./testplan.json cargo test ``` -------------------------------- ### Using macro-free runtime from commons Source: https://github.com/allure-framework/allure-rust/blob/main/README.md Use this snippet when attribute macros are not allowed. It uses the macro-free runtime from allure_rust_commons to run a test with Allure context. ```rust use allure_rust_commons as allure; #[test] fn test_with_allure_runtime() { allure::test(|| { allure::feature("Authentication"); allure::stage("open login page"); allure::log_step("open login page"); }); } ``` -------------------------------- ### Per-connection wiring with AllureInstrumentation Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-diesel/README.md Attach the instrumentation to a connection after establishing it. Every query executed on that connection is then recorded against whichever Allure test is running on the current thread. ```rust use diesel::prelude::*; use diesel::sqlite::SqliteConnection; fn connect() -> ConnectionResult { let mut conn = SqliteConnection::establish(":memory:")?; conn.set_instrumentation(allure_diesel::AllureInstrumentation::new()); Ok(conn) } ``` -------------------------------- ### Use AllureReqwestClient wrapper client Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-reqwest/README.md Alternative approach with the smallest dependency surface, instrumenting only a few calls. Does not require `reqwest-middleware`; calls must be sent through `AllureReqwestClient::send` or `AllureReqwestClient::execute`. ```rust use allure_reqwest::AllureReqwestClient; async fn create_order(allure: allure_rust_commons::AllureFacade) -> reqwest::Result<()> { let client = AllureReqwestClient::new(allure); let response = client .send( client .post("https://api.example.com/v1/orders") .header("content-type", "application/json") .body(r#"{"name":"demo"}"#), ) .await?; response.error_for_status()?; Ok(()) } ``` -------------------------------- ### Workspace run profile: allure agent with cargo test --workspace Source: https://github.com/allure-framework/allure-rust/blob/main/docs/allure-test-agent.md Broad default workspace validation. Does not include non-default feature profiles such as allure-reqwest/middleware; the smoke project is excluded from the workspace. Use a temporary results directory via ALLURE_RESULTS_DIR. ```bash TMP_DIR="$(mktemp -d)" && ALLURE_RESULTS_DIR="$TMP_DIR/allure-results" allure agent --goal "" -- cargo test --workspace --all-targets ``` -------------------------------- ### Add allure-reqwest as a dev dependency Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-reqwest/README.md Use `cargo add` to add the crate as a development dependency. ```bash cargo add allure-reqwest --dev ``` -------------------------------- ### Add labels for only test files Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-cargotest/README.md Add a [[package.metadata.allure.modules]] entry with path to apply labels to every #[allure_test] in that file. ```toml [[package.metadata.allure.modules]] path = "tests/payments.rs" labels = { a = "a-value", b = ["b-value1", "b-value2"] } ``` -------------------------------- ### Attach AllureReqwestMiddleware to a middleware client Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-reqwest/README.md Recommended approach for broad capture with minimal call-site changes. Middleware runs around each request made through a `reqwest_middleware::ClientWithMiddleware`, recording request, response, timing, and errors automatically. ```rust use allure_reqwest::AllureReqwestMiddleware; use reqwest_middleware::ClientBuilder; async fn create_order(allure: allure_rust_commons::AllureFacade) -> reqwest::Result<()> { let client = ClientBuilder::new(reqwest::Client::new()) .with(AllureReqwestMiddleware::new(allure)) .build(); let response = client .post("https://api.example.com/v1/orders") .header("content-type", "application/json") .body(r#"{"name":"demo"}"#) .send() .await?; response.error_for_status()?; Ok(()) } ``` -------------------------------- ### Add allure-cargotest for regular tests Source: https://github.com/allure-framework/allure-rust/blob/main/README.md Adds the allure-cargotest crate as a dev dependency for automatic test lifecycle wiring. ```bash cargo add allure-cargotest --dev ``` -------------------------------- ### Override results directory with ALLURE_RESULTS_DIR Source: https://github.com/allure-framework/allure-rust/blob/main/README.md Sets the ALLURE_RESULTS_DIR environment variable to change where test results are written. Default is target/allure-results. ```bash ALLURE_RESULTS_DIR=./allure-results cargo test ``` -------------------------------- ### Async test with #[allure_test] and #[tokio::test] Source: https://github.com/allure-framework/allure-rust/blob/main/README.md Composes #[allure_test] with a runtime-specific test macro such as #[tokio::test]. Add and configure Tokio in your test crate; allure-cargotest does not depend on Tokio. Allure context is available in the root async test body and awaited helpers; implicit propagation into independently spawned tasks is not guaranteed. Async tests may also return Result<(), E>, ExitCode, custom Termination, or impl Termination values when the runtime-specific test macro supports them. ```rust use allure_cargotest::allure_test; #[allure_test] #[tokio::test] async fn async_test_with_allure() { allure.feature("Async API"); tokio::task::yield_now().await; allure.parameter("runtime", "tokio"); } ``` -------------------------------- ### Cargotest e2e run profile: allure agent with cargo test -p allure-cargotest Source: https://github.com/allure-framework/allure-rust/blob/main/docs/allure-test-agent.md Validates macro/test-plan/e2e sample behavior. Nested Cargo runs can be slower and may need dependency cache access. Use a temporary results directory via ALLURE_RESULTS_DIR. ```bash TMP_DIR="$(mktemp -d)" && ALLURE_RESULTS_DIR="$TMP_DIR/allure-results" allure agent --goal "" -- cargo test -p allure-cargotest --all-targets ``` -------------------------------- ### Add labels for only some Rust modules Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-cargotest/README.md Add a [[package.metadata.allure.modules]] entry with module path to apply labels to tests in that module and its submodules. ```toml [[package.metadata.allure.modules]] module = "org::example" labels = { a = "a-value", b = ["b-value1", "b-value2"] } ``` -------------------------------- ### Add labels for all tests in a package Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-cargotest/README.md Add labels under [package.metadata.allure.labels] in Cargo.toml to apply to every #[allure_test] in the package. String array values add the same label multiple times. ```toml [package.metadata.allure.labels] a = "a-value" b = ["b-value1", "b-value2"] ``` -------------------------------- ### Enable middleware feature in Cargo.toml Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-reqwest/README.md Required dependencies for using the middleware approach. The `middleware` feature must be enabled. ```toml [dependencies] allure-reqwest = { version = "1", features = ["middleware"] } reqwest = "0.12" reqwest-middleware = "0.4" ``` -------------------------------- ### Smoke script run profile: allure agent with check-cargotest-smoke.sh Source: https://github.com/allure-framework/allure-rust/blob/main/docs/allure-test-agent.md Validates the excluded smoke project full-name contract. Covers the smoke project, not the full workspace. Use ALLURE_SMOKE_RESULTS_DIR for a temporary results directory. ```bash TMP_DIR="$(mktemp -d)" && ALLURE_SMOKE_RESULTS_DIR="$TMP_DIR/smoke-allure-results" allure agent --goal "" -- bash ./scripts/check-cargotest-smoke.sh ``` -------------------------------- ### Smoke script nextest run profile: ALLURE_SMOKE_RUNNER=nextest Source: https://github.com/allure-framework/allure-rust/blob/main/docs/allure-test-agent.md Validates that result files stay unique when every test runs in its own process. Requires cargo-nextest and covers the smoke project only. Use ALLURE_SMOKE_RESULTS_DIR for a temporary results directory. ```bash TMP_DIR="$(mktemp -d)" && ALLURE_SMOKE_RUNNER=nextest ALLURE_SMOKE_RESULTS_DIR="$TMP_DIR/smoke-allure-results" allure agent --goal "" -- bash ./scripts/check-cargotest-smoke.sh ``` -------------------------------- ### Override assertion logging with ALLURE_LOG_ASSERTS Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-cargotest/README.md Use ALLURE_LOG_ASSERTS environment variable to override the package setting for a run. Set to true or false. ```bash ALLURE_LOG_ASSERTS=true cargo test ``` ```bash ALLURE_LOG_ASSERTS=false cargo test ``` -------------------------------- ### Log assertions in helper functions with #[log_asserts] Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-cargotest/README.md Add #[log_asserts] to helper functions not annotated with #[allure_test] or #[step] to log assertions inside them. ```rust use allure_cargotest::{allure_test, log_asserts}; #[log_asserts] fn check_response() { assert_eq!(200, 200); } #[allure_test] #[test] fn response_is_ok() { check_response(); } ``` -------------------------------- ### Use #[allure_test] with #[tokio::test] for async tests Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-cargotest/README.md Place #[allure_test] above #[tokio::test] in a test crate that depends on Tokio; allure-cargotest does not depend on Tokio. The root async test body and awaited helpers can use Allure metadata and steps, but independently spawned Tokio tasks do not implicitly inherit the current Allure context. ```rust use allure_cargotest::allure_test; #[allure_test] #[tokio::test] async fn login_works_async() { allure.feature("Authentication"); tokio::task::yield_now().await; allure.parameter("runtime", "tokio"); } ``` -------------------------------- ### Disable assertion logging via Cargo metadata Source: https://github.com/allure-framework/allure-rust/blob/main/crates/allure-cargotest/README.md Set log_asserts to false in [package.metadata.allure] to disable assertion logging globally for a package. ```toml [package.metadata.allure] log_asserts = false ```