Announcing behave 0.8.0: BDD-style Rust tests that compile to ordinary #[test] functions

⚓ Rust    📅 2026-03-17    👤 surdeus    👁️ 2      

surdeus

Hi everyone :waving_hand:

I’ve published behave 0.8.0, a behavior-driven testing library for Rust.

The main goal is simple:

make tests easier to read and structure without introducing a custom test runtime

behave! lets you write nested scenario-style suites, and the generated tests still compile down to ordinary #[test] functions, so you can keep using normal Rust tooling and cargo test.

A few things behave focuses on:

  • nested, readable test groups
  • inherited setup / teardown
  • expressive expect! assertions
  • parameterized tests with each and matrix
  • tags, focus/pending workflow, and conditional skipping
  • optional cargo-behave CLI for tree output, JSON/JUnit output, watch mode, and tag filtering

Minimal example:

use behave::prelude::*;

behave! {
    "checkout totals" {
        setup {
            let prices = [120, 80, 40];
            let subtotal: i32 = prices.iter().sum();
        }

        "adds line items" {
            expect!(subtotal).to_equal(240)?;
        }

        "renders a receipt line" {
            let receipt = format!("subtotal={subtotal}");
            expect!(receipt).to_contain_substr("240")?;
        }
    }
}

In 0.8.0, I also added new matcher packs for JSON, HTTP, and URLs, plus more collection/path/string matchers and an each_type DSL for typed test generation.

I’d especially love feedback on:

  • DSL ergonomics
  • matcher API design
  • where this fits relative to more conventional Rust test styles
  • what feels unnecessary or too magical

Cheers!

GitHub
Crates.io
Docs.rs

1 post - 1 participant

Read full topic

🏷️ Rust_feed