#test-framework #bdd #async #atdd #test-runner

dev cucumber

Cucumber testing framework for Rust, with async support. Fully native, no external test runners or dependencies.

37 releases

0.21.1 Jun 16, 2024
0.20.2 Dec 4, 2023
0.20.1 Oct 16, 2023
0.20.0 Jul 10, 2023
0.1.0 Mar 29, 2016

#32 in Asynchronous

Download history 20418/week @ 2024-08-14 19801/week @ 2024-08-21 18943/week @ 2024-08-28 25700/week @ 2024-09-04 21720/week @ 2024-09-11 25235/week @ 2024-09-18 22236/week @ 2024-09-25 24094/week @ 2024-10-02 18581/week @ 2024-10-09 25622/week @ 2024-10-16 26268/week @ 2024-10-23 136969/week @ 2024-10-30 176468/week @ 2024-11-06 164925/week @ 2024-11-13 152021/week @ 2024-11-20 47791/week @ 2024-11-27

573,365 downloads per month
Used in 28 crates (24 directly)

MIT/Apache

530KB
10K SLoC

Cucumber testing framework for Rust

crates.io Rust 1.75+ Unsafe Forbidden
CI Rust docs

An implementation of the Cucumber testing framework for Rust. Fully native, no external test runners or dependencies.

Usage

Describe testing scenarios in .feature files:

Feature: Eating too much cucumbers may not be good for you
    
  Scenario: Eating a few isn't a problem
    Given Alice is hungry
    When she eats 3 cucumbers
    Then she is full

Implement World trait and describe steps:

use std::time::Duration;

use cucumber::{given, then, when, World as _};
use tokio::time::sleep;

#[derive(cucumber::World, Debug, Default)]
struct World {
    user: Option<String>,
    capacity: usize,
}

#[given(expr = "{word} is hungry")] // Cucumber Expression
async fn someone_is_hungry(w: &mut World, user: String) {
    sleep(Duration::from_secs(2)).await;
    
    w.user = Some(user);
}

#[when(regex = r"^(?:he|she|they) eats? (\d+) cucumbers?$")]
async fn eat_cucumbers(w: &mut World, count: usize) {
    sleep(Duration::from_secs(2)).await;

    w.capacity += count;
    
    assert!(w.capacity < 4, "{} exploded!", w.user.as_ref().unwrap());
}

#[then("she is full")]
async fn is_full(w: &mut World) {
    sleep(Duration::from_secs(2)).await;

    assert_eq!(w.capacity, 3, "{} isn't full!", w.user.as_ref().unwrap());
}

#[tokio::main]
async fn main() {
    World::run("tests/features/readme").await;
}

Add test to Cargo.toml:

[[test]]
name = "readme"
harness = false  # allows Cucumber to print output instead of libtest

For more examples check out the Book (current | edge).

Cargo features

Supporting crates

The full gamut of Cucumber's Gherkin language is implemented by the gherkin crate. Most features of the Gherkin language are parsed already and accessible via the relevant structs.

Known issues

  • Scenario Outline is treated the same as Outline or Example in the parser (gherkin/#19).

License

This project is licensed under either of

at your option.

Dependencies

~10–22MB
~319K SLoC