rstest
rstest copied to clipboard
Reusing test data with different expected output across tests?
I can't find a way to do this with either rstest
or rstest_reuse
, and it'd be very useful for my case. I have a bunch of defined instantiations of a struct against which I'd like to test different operations. But while each of these test functions (one for each operation) take the same list of struct data, the expected output of the operation is different. Is there a way to combine the test data with different expected results for each test?
The closest I got was with something like this:
#[template]
#[rstest]
#[case(2, 2)]
#[case(2, 3)]
fn two_simple_cases(#[case] a: u32, #[case] b: u32) {}
#[apply(two_simple_cases)]
fn it_works(a: u32, b: u32, #[values(true, false)] expected: bool) {
assert_eq!(a == b, expected);
}
However, this performs every combination of the input and the expected value: (2, 2, true), (2, 2, false), (2, 3, true), (2, 3, false). How can I do something like the above that will result in the cases: (2, 2, true), (2, 3, false)?