| Crates.io | cucumber-trellis |
| lib.rs | cucumber-trellis |
| version | 0.1.4 |
| created_at | 2024-06-03 07:13:09.583047+00 |
| updated_at | 2024-07-05 17:47:39.401611+00 |
| description | Create a test "trellis" for Cucumber |
| homepage | |
| repository | https://github.com/corebreaker/cucumber-trellis |
| max_upload_size | |
| id | 1259776 |
| size | 18,208 |
Create a test "trellis" for Cucumber.
You can create a test suite for Cucumber, with each test implemented in a file, linked to a Gherkin feature file.
Each test implements a trait CucumberTest and this test is registered in the "trellis".
Finally, all tests are executed in parallel, and the trellis waits for all tests to finish.
cargo add cucumber cucumber-trellis
First, allows Cucumber to print output instead of libtest
by adding these lines in your Cargo.toml:
[[test]]
name = "cucumber"
harness = false
Then, put feature files in tests/features directory,
and put the following code in tests/cucumber.rs:
mod tests;
fn main() {
let mut trellis = cucumber_trellis::CucumberTrellis::new(None);
trellis.add_test::<tests::example::SimpleTest>();
trellis.run_tests();
}
After that , in tests/tests/example.rs,
implements the trait cucumber_trellis::CucumberTest, like this:
use cucumber_trellis::CucumberTest;
use cucumber::World;
#[derive(World, Debug)]
pub(in super::super) struct SimpleTest;
impl CucumberTest for SimpleTest {
const NAME: &'static str = "simple-test";
}
// Implement here, the steps according the file `tests/features/simple-test.feature`
// ...
Don't forget the file tests/tests/mod.rs:
pub(super) mod example;
Finally, run the tests:
cargo test --test cucumber
You have an example in the tests directory.
You can use the macro cucumber_trellis::cucumber_test to simplify the code.
The macro cucumber_test will decorate your function that will add Cucumber tests.
That function will receive a mutable reference to a CucumberTrellis object:
use cucumber_trellis::{CucumberTrellis, cucumber_test};
#[cucumber_test(features="tests/features", executor="futures::executor::block_on", use_tokio)]
fn my_tests(trellis: &mut CucumberTrellis) {
trellis.add_test::<tests::example::SimpleTest>();
}
Currently, the macro cucumber_test can receive the following parameters:
features: The path to the features directory, here for example tests/features.executor: The path of a function to execute asyncs.use_tokio: The generated function main will use the tokio runtime;
Tokio should be added in dev-dependencies.These parameters are optional, and the parameters use_tokio and executor are mutually exclusive,
as use_tokio forces the use of the tokio as executor.
So the example above won't compile, it's just to show the usage.
The default executor is futures::executor::block_on,
therefore the dependency futures must be added in Cargo.toml if no executor is specified in parameters.