Crate allure_rs

Crate allure_rs 

Source
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§

AllureConfig
Configuration for the Allure runtime.
AllureConfigBuilder
Builder for configuring the Allure runtime.
AllureWriter
Writer for Allure test result files.
Attachment
Attachment file reference.
CategoriesBuilder
Categories configuration builder.
Category
Category definition for defect classification.
EnvironmentBuilder
Environment info builder for generating environment.properties.
FixtureResult
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.
StatusDetails
Additional status details for test results and steps.
StepResult
Step result within a test.
TestContext
Test context holding the current test result and step stack.
TestResult
Main test result structure written to {uuid}-result.json.
TestResultContainer
Container for test fixtures (setup/teardown). Written to {uuid}-container.json.

Enums§

AllureError
Errors that can occur during Allure operations.
ContentType
Content type for attachments.
LabelName
Reserved label names used by Allure for special purposes.
LinkType
Link type for external references.
ParameterMode
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§

AllureResult
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.