Expand description
§Allure-RS
A comprehensive Rust library for generating Allure test reports.
This crate provides full feature parity with allure-js-commons, including:
- Test metadata annotations (epic, feature, story, severity, owner, tags)
- Test steps with nesting support
- Attachments (text, JSON, binary files)
- BDD-style steps (given, when, then)
- Links to issue trackers and test management systems
- Flaky test support
- Environment and categories configuration
§Quick Start
Add this to your Cargo.toml:
[dev-dependencies]
allure-rs = "0.1"§Basic Usage
ⓘ
use allure_rs::prelude::*;
// Note: Metadata attributes must come BEFORE #[allure_test]
#[allure_epic("User Management")]
#[allure_feature("Authentication")]
#[allure_severity("critical")]
#[allure_test]
fn test_login() {
step("Initialize user", || {
// setup code
});
step("Perform login", || {
// test code
assert!(true);
});
attachment::text("Debug info", "Login successful");
}§BDD Style
ⓘ
use allure_rs::prelude::*;
#[allure_test]
fn test_user_registration() {
bdd::given("a new user with valid email", || {
// setup
});
bdd::when("the user submits registration form", || {
// action
});
bdd::then("the user account should be created", || {
assert!(true);
});
}§Configuration
ⓘ
use allure_rs::configure;
// Initialize before running tests (e.g., in a test setup or main)
configure()
.results_dir("allure-results")
.clean_results(true)
.init()
.unwrap();§Environment Info
ⓘ
use allure_rs::environment;
environment()
.set("rust_version", env!("CARGO_PKG_RUST_VERSION"))
.set("os", std::env::consts::OS)
.set_from_env("CI", "CI")
.write()
.unwrap();§Categories
ⓘ
use allure_rs::{categories, Category, Status};
categories()
.with_product_defects()
.with_test_defects()
.with_category(
Category::new("Infrastructure Issues")
.with_status(Status::Broken)
.with_message_regex(".*timeout.*")
)
.write()
.unwrap();Modules§
- attachment
- Attachment helper module with convenience functions.
- bdd
- BDD-style step functions for behavior-driven testing.
- enums
- Allure enums for test result status, stage, severity, and other classifications.
- error
- Error types for Allure operations.
- model
- Allure data model types for test results, steps, attachments, and containers.
- prelude
- Prelude module for convenient imports.
- runtime
- Runtime context management for tracking test execution state.
- writer
- File writer for Allure test results, containers, and attachments.
Macros§
- allure_
step - Macro for inline step definition.
Structs§
- Allure
Config - Configuration for the Allure runtime.
- Allure
Config Builder - Builder for configuring the Allure runtime.
- Allure
Writer - Writer for Allure test result files.
- Attachment
- Attachment file reference.
- Categories
Builder - Categories configuration builder.
- Category
- Category definition for defect classification.
- Environment
Builder - Environment info builder for generating
environment.properties. - Fixture
Result - Fixture result (setup or teardown).
- Label
- Label for categorizing and filtering tests.
- Link
- External link associated with a test.
- Parameter
- Test parameter with optional display options.
- Status
Details - Additional status details for test results and steps.
- Step
Result - Step result within a test.
- Test
Context - Test context holding the current test result and step stack.
- Test
Result - Main test result structure written to
{uuid}-result.json. - Test
Result Container - Container for test fixtures (setup/teardown).
Written to
{uuid}-container.json.
Enums§
- Allure
Error - Errors that can occur during Allure operations.
- Content
Type - Content type for attachments.
- Label
Name - Reserved label names used by Allure for special purposes.
- Link
Type - Link type for external references.
- Parameter
Mode - Parameter display mode in reports.
- Severity
- Test severity level for prioritization.
- Stage
- Test execution stage.
- Status
- Test result status indicating the outcome of a test.
Constants§
- DEFAULT_
RESULTS_ DIR - Default directory for Allure results.
Functions§
- allure_
id - Adds an Allure ID label to the current test.
- attach_
binary - Attaches binary content to the current test or step.
- attach_
file - Attaches a file from the filesystem to the current test or step.
- attach_
json - Attaches JSON content to the current test or step.
- attach_
text - Attaches text content to the current test or step.
- categories
- Creates a new categories builder.
- compute_
history_ id - Computes the history ID for a test based on its full name and parameters.
- configure
- Configures the Allure runtime.
- description
- Sets the test description (markdown).
- description_
html - Sets the test description (HTML).
- display_
name - Sets the display name for the current test.
- environment
- Creates a new environment builder.
- epic
- Adds an epic label to the current test.
- feature
- Adds a feature label to the current test.
- flaky
- Marks the current test as flaky.
- generate_
uuid - Generates a new UUID v4 string.
- issue
- Adds an issue link to the current test.
- known_
issue - Marks the current test as having a known issue.
- label
- Adds a label to the current test.
- link
- Adds a generic link to the current test.
- log_
step - Logs a step without a body (for simple logging).
- muted
- Marks the current test as muted.
- owner
- Adds an owner label to the current test.
- parameter
- Adds a parameter to the current test or step.
- parameter_
excluded - Adds a parameter excluded from history ID calculation.
- parameter_
hidden - Adds a parameter hidden from display (value not shown in the report).
- parameter_
masked - Adds a parameter with a masked value (e.g., passwords).
- parent_
suite - Adds a parent suite label to the current test.
- run_
test - Runs a test function with Allure tracking.
- severity
- Adds a severity label to the current test.
- skip
- Marks the current test as skipped and finalizes the result.
- step
- Executes a step with the given name and body.
- story
- Adds a story label to the current test.
- sub_
suite - Adds a sub-suite label to the current test.
- suite
- Adds a suite label to the current test.
- tag
- Adds a tag label to the current test.
- tags
- Adds multiple tag labels to the current test.
- test_
case_ id - Sets the test case ID for the current test.
- title
- Sets a custom title for the current test.
- tms
- Adds a TMS link to the current test.
- with_
async_ context - Executes an async block with a thread-local test context (non-tokio fallback).
- with_
context - Executes a function with the current test context.
Type Aliases§
- Allure
Result - Result type alias for Allure operations.
Attribute Macros§
- allure_
description - Adds a description to a test (markdown format).
- allure_
description_ html - Adds an HTML description to a test.
- allure_
epic - Adds an epic label to a test.
- allure_
epics - Adds multiple epic labels to a test.
- allure_
feature - Adds a feature label to a test.
- allure_
features - Adds multiple feature labels to a test.
- allure_
flaky - Marks a test as flaky.
- allure_
id - Adds an ID label to a test.
- allure_
issue - Adds an issue link to a test.
- allure_
link - Adds a generic link to a test.
- allure_
owner - Adds an owner label to a test.
- allure_
parent_ suite - Adds a parent suite label to a test.
- allure_
severity - Adds a severity label to a test.
- allure_
step_ fn - Attribute macro that marks a function as an Allure step.
- allure_
stories - Adds multiple story labels to a test.
- allure_
story - Adds a story label to a test.
- allure_
sub_ suite - Adds a sub-suite label to a test.
- allure_
suite - Attribute macro that groups tests in a module under a suite.
- allure_
suite_ label - Adds a suite label to a test.
- allure_
tag - Adds tag labels to a test.
- allure_
tags - Adds multiple tag labels to a test.
- allure_
test - Attribute macro that wraps a test function with Allure tracking.
- allure_
title - Sets a custom title for a test.
- allure_
tms - Adds a TMS link to a test.