rstest 0.2.0

A simple `pytest` clone for Rust. It use procedural macro to implement fixtures and table based tests.
docs.rs failed to build rstest-0.2.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: rstest-0.19.0

A simple pytest clone for Rust

rstest use procedural macro to implement simple fixtures and table based tests. To use it you need at least 1.30 toolchain (beta channel till 2018-10-25) and add follow lines to your Cargo.toml file:

[dev-dependencies]
rstest = "0.2"

The core idea is that every input arguments of your test function will be resolved by call a function with the same name. You can also use mut argument or generic types.

Example:

#[cfg(test)]
extern crate rstest;

use rstest::rstest;

pub fn fixture() -> u32 { 42 }

#[rstest]
fn should_success(fixture: u32) {
    assert_eq!(fixture, 42);
}

#[rstest]
fn should_fail(fixture: u32) {
    assert_ne!(fixture, 42);
}

Moreover you can use rstest_parametrize attribute to implement table based tests. An example is the best way to explain it

#[cfg(test)]
extern crate rstest;

use rstest::rstest_parametrize;

#[rstest_parametrize(
    expected, input,
    case(4, "ciao"),
    case(3, "Foo")
)]
fn strlen_test(expected: usize, input: &str) {
    assert_eq!(expected, input.len());
}

You can find more examples in resources directory and in rs8080 that use this module intensely.

License

Licensed under either of

at your option.