Awesome Open Source
Awesome Open Source


Documentation Actions Status

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

The 0.6.x macro has been removed. If you need to use this macro, please continue to use the 0.6 version.


Create a directory called tests/ in your project root and create a test target of your choice. In this example we will name it

Add this to your Cargo.toml:

name = "cucumber"
harness = false # Allows Cucumber to print output instead of libtest

cucumber = { package = "cucumber_rust", version = "^0.7.0" } 

Create a directory called features/ and put a feature file in it named something like example.feature. It might look like:

Feature: Example feature

  Scenario: An example scenario
    Given I am trying out Cucumber
    When I consider what I am doing
    Then I am interested in ATDD
    And we can implement rules with regex

And here's an example of implementing those steps using our tests/ file:

use async_trait::async_trait;
use std::{convert::Infallible, cell::RefCell};

pub struct MyWorld {
    // You can use this struct for mutable context in scenarios.
    foo: String,
    bar: usize,
    some_value: RefCell<u8>,

impl MyWorld {
    async fn test_async_fn(&mut self) {
        *self.some_value.borrow_mut() = 123u8; = 123;

impl cucumber::World for MyWorld {
    type Error = Infallible;

    async fn new() -> Result<Self, Infallible> {
        Ok(Self {
            foo: "wat".into(),
            bar: 0,
            some_value: RefCell::new(0),

mod example_steps {
    use cucumber::{Steps, t};

    pub fn steps() -> Steps<crate::MyWorld> {
        let mut builder: Steps<crate::MyWorld> = Steps::new();

                "a thing",
                t!(|mut world, _step| {
           = "elho".into();
                "something goes (.*)",
                t!(|world, _matches, _step| world),
                "I am trying out Cucumber",
                |mut world: crate::MyWorld, _step| {
           = "Some string".to_string();
            .when("I consider what I am doing", |mut world, _step| {
                let new_string = format!("{}.", &;
       = new_string;
            .then("I am interested in ATDD", |world, _step| {
                assert_eq!(, "Some string.");
                r"^we can (.*) rules with regex$",
                |world, matches, _step| {
                    // And access them as an array
                    assert_eq!(matches[1], "implement");


fn main() {
    // Do any setup you need to do before running the Cucumber runner.
    // e.g. setup_some_db_thing()?;

    let runner = cucumber::Cucumber::<MyWorld>::new()

    // You may choose any executor you like (Tokio, async-std, etc)
    // You may even have an async main, it doesn't matter. The point is that
    // Cucumber is composable. :)

You can then run your Cucumber tests by running this command:

cargo test --test cucumber

Supporting crates

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


This project is licensed under either of

at your option.

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
hacktoberfest (4,449
rust (3,874
tdd (149
bdd (81
cucumber (47

Find Open Source By Browsing 7,000 Topics Across 59 Categories