Skip to main content

test_with_fixtures

Attribute Macro test_with_fixtures 

Source
#[test_with_fixtures]
Expand description

Turns a test whose parameters are fixtures into a runnable #[test].

Each parameter name: T is resolved by calling the same-named fixture function fn name() -> TestResult<T> and ?-propagating its result, so a fixture failure aborts the test as an ErrorKind::Setup error before the body runs. The parameters are resolved left to right.

Because the resolved fixtures are ?-propagated, the test must return a type that ? accepts, the usual -> TestResult shape.

use test_better::prelude::*;

#[fixture]
fn name() -> TestResult<String> {
    Ok(String::from("alice"))
}

#[test_with_fixtures]
fn greets_by_name(name: String) -> TestResult {
    check!(name.as_str()).satisfies(eq("alice"))
}