[][src]Attribute Macro rstest::rstest_matrix

#[rstest_matrix]
Deprecated since 0.5.0:

Please use #[rstest(...)] instead

Write matrix-based tests: you must indicate arguments and values list that you want to test and rstest_matrix generate an indipendent test for each argument combination (the carthesian product of values lists).

#[rstest_matrix(
    foo => [42, 24],
    bar => ["foo", "bar"]
)]
fn matrix_test(foo: u32, bar: &str) {
    //... test body
}

Running cargo test in this case executes four tests:

running 4 tests
test matrix_test::case_1_1 ... ok
test matrix_test::case_1_2 ... ok
test matrix_test::case_2_1 ... ok
test matrix_test::case_2_2 ... ok

test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Like in [rstest] you can inject fixture values and every parameter that isn't mapped in case()s will be resolved as default fixture.

In general rstest_matrix's syntax is:

rstest_matrix(
    ident_1 => [val_1_1, ..., val_1_m1],
    ....
    ident_n => [val_n_1, ..., val_n_mn][,]
    [fixture_1(...]
    [...,]
    [fixture_k(...)]
    [::attribute_1[:: ... [::attribute_k]]]
)
  • ident_x should be a valid function argument name
  • val_x_y should be a valid rust expression that can be assigned to ident_x function argument
  • fixture_v(...) should be a valid function argument and a [fixture] fixture function
  • attributes now can be just trace or notrace(args..) (see [rstest]

Function's arguments can be present just once as identity or fixture.

Functions marked by rstest_matrix can use generics, impl and dyn without any restriction.

#[rstest_matrix(
    foo => ["foo", String::from("foo")]
)]
fn len<S: AsRef<str>>(foo: S) {
    assert_eq!(3, input.as_ref().len())
}

#[rstest_matrix(
    foo => ["foo", String::from("foo")]
)]
fn len_by_impl(foo: impl AsRef<str>) {
    assert_eq!(3, input.as_ref().len())
}