Crates.io | litmus |
lib.rs | litmus |
version | 0.5.5 |
created_at | 2025-04-07 08:42:02.300293+00 |
updated_at | 2025-09-12 02:21:18.378644+00 |
description | a macro-free BDD test harness. |
homepage | |
repository | https://github.com/NTDuck/litmus |
max_upload_size | |
id | 1623824 |
size | 192,243 |
a macro-free BDD test harness.
inspired by cucumber and rspec.
litmus
With litmus
, you can ...
write tests declaratively
with minimal overhead
all without using macros.
Add this to your Cargo.toml
:
# ./Cargo.toml
[dev-dependencies]
litmus = "0.5.5"
Disable the default harness for your test targets:
# ./Cargo.toml
[[test]]
name = ...
path = ...
harness = false
The following example replicates the cucumber-rs example.
/// ./examples/hello-world.rs
#[derive(::core::default::Default)]
struct World {
user: ::core::option::Option<String>,
capacity: usize,
}
#[rustfmt::skip]
fn main() -> ::std::process::ExitCode {
::litmus::Runner::new()
.feature(::litmus::Feature::new()
.description("Eating too much cucumbers may not be good for you")
.scenario(::litmus::Scenario::<World>::new()
.description("Eating a few isn't a problem")
.given("Alice is hungry", |w| w.user = Some("Alice".to_owned()))
.when("she eats 3 cucumbers", |w| {
w.capacity += 3;
::litmus::assert!(w.capacity < 4, "Alice exploded")
})
.then("she is full", |w| ::litmus::assert!(w.capacity == 3, "Alice isn't full!"))))
.run()
}
# ./Cargo.toml
[[example]]
name = "hello-world"
path = "./examples/hello-world.rs"
harness = false
We recommend cargo-nextest for a better experience, although cargo-test is supported.
$ cargo nextest run --example hello-world
Finished `test` profile [unoptimized + debuginfo] target(s) in 0.14s
────────────
Nextest run ID 72000e08-3cd4-4b80-a32d-a50a382f1673 with nextest profile: default
Starting 1 test across 1 binary
PASS [ 0.007s] litmus::example/hello-world Eating a few isn't a problem
────────────
Summary [ 0.008s] 1 test run: 1 passed, 0 skipped
$ cargo test --example hello-world
Finished `test` profile [unoptimized + debuginfo] target(s) in 0.17s
Running unittests examples/hello-world.rs (target/debug/examples/hello_world-06cfa831d0c9efe7)
running 1 test
test Eating a few isn't a problem ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
More examples are available in the examples/
directory.
This project is licensed under the BSD 3-Clause License.